Bài 11: mảng trong c

1. For example, the opening

Consider the example entry 5 integer, output khổng lồ the screen 5 Amuốn them on a line và total 5 which.

You watching: Bài 11: mảng trong c

// e.g about array - code by nguyenvanquan7826#include int main() int a, b, c, d, e; // 5 bien printf("Nhap a = "); scanf("%d", &a); printf("Nhap b = "); scanf("%d", &b); printf("Nhap c = "); scanf("%d", &c); printf("Nhap d = "); scanf("%d", &d); printf("Nhap e = "); scanf("%d", &e); int tong = a + b + c + d + e; printf("Tong cua %d + %d + %d + %d + %d = %d ", a, b, c, d, e, tong); return 0;Result:

Nhap a = 3 Nhap b = 5 Nhap c = 3 Nhap d = 6 Nhap e = 1 Tong crab 3 + 5 + 3 + 6 + 1 = 18

As examples we see entering all 5 và we made some screen seems very hard & we had to lớn use too many variables, if the number of variables that we are not 5 that is 50, 500,... Then this result is very difficult. To remedy this we use the array.

A phối of array elements with the same type of data. Array of arrays 1 evening, 2 evening,... And each type of data, there 1 corresponding array (integer array, real array, character array (Chain)),... I mainly consider the array 1 dimensional array 2 evening.

Now we will solve the examples on using arrays 1 evening.

2. Arrays 1 evening

2.1 Example overview

Have you tried to lớn read & run this program, then please see details below.

// e.g about array - code by nguyenvanquan7826#include int main() { // knhì bao mang a teo n phan tu int n = 5, i, s = 0; int a; // thuc hien nhap tung phan tu sở hữu for (i = 0; i Import a<0> = 3 Import a<1> = 4 Import a<2> = 6 Import a<3> = 2 Import a<4> = 7 Bring entered 3 4 6 2 7 Sum of the carrying: 22

2.2 How to lớn declare array 1 evening

KieuDuLieu TenMang ;

CEO: int a<10>;

Arrays 1 afternoon included a 10 elements of type integer. After declaring have sầu 1 array looks like this:


Retrieve sầu array in C

2.4 How lớn import và export the elements of the array

To enter data for the elements in the array we need to lớn browse to lớn each element in the array và proceed to lớn enter a loop

for (i = 0; i The publication of the elements in the array are also conducted similar:

for (i = 0; i

2.5 Enter output array using function

In many problem, we have lớn enter multiple arrays, & output multiple times, Meanwhile let"s put on a function for easy entry và use.

See more: Top 5 Phần Mềm Tạo Banner Chuyên Nghiệp, Hay Nhất, Top 5 Phần Mềm Tạo Banner Chuyên Nghiệp, Hay Nhất

// e.g about array - code by nguyenvanquan7826#include void nhapMang(int a<>, int n) { int i; // thuc hien nhap tung phan tu sở hữu for (i = 0; i Noted: An array of relationships with 1 pointer, array so as 1 pointer lớn the array passed khổng lồ the function, the elements of the array will be affected if there are any changes in the array.

2.6 A few other notes

Initialize the array: We can initialize the array in the declaration immediately. CEO: float a <5> = 3.4, 5, 6, 7, 4,2With this initialization if we initialize exceed 5 element will report an error, without any element is the element that is the value 0.CEO: float a <5> = 3.4, 5, 7 => a<4> = 0.CEO: float a <5> = 3.4, 5, 7, 1, 2, 3 => Machine error.Also we have sầu khổng lồ declare và initialize a previously unknown number of array.CEO: int a<> = 3,6,2,5 => Array with 4 receiving element corresponding values.Or: int a<>; => Often used when using arrays as parameters in function form.

3. Arrays 2 evening

We can consider it as a matrix. The nature, declaring, Import-Export,... Similar array 1 evening.

KieuDuLieu TenMang ;

VD report: int a<5><10>; => Array a composed 5 goods và 10 post (each row 10 element).

See more: Vũ Khí Tự Vệ - Các Loại Dụng Cụ Tự Vệ Hợp Pháp Năm 2020


Organization, storage array 2 way in C


Enter into an array, find the biggest & the smallest number in the array entered.Enter a series of numbers, print out the location of the largest (can have multiple locations).Enter a sequence of precipitation is consecutive month in year. The notice of the May rainfall than the average rainfall of the month.Enter a series of numbers, sorted và printed in ascending sequence.Entered inlớn a matrix (Plate 2 evening). Print out the sum of each row of the matrix.