1. For example, the opening

Consider the example entry 5 integer, output lớn the screen 5 Ahy vọng them on a line & total 5 which.

You watching: 2

// 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 and we made some screen seems very hard & we had to 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 mix 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 read & run this program, then please see details below.

// e.g about array - code by nguyenvanquan7826#include int main() { // knhị bao mang a co 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 declare array 1 evening

KieuDuLieu TenMang ;

CEO: int a<10>;

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


Retrieve sầu array in C

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

To enter data for the elements in the array we need khổng lồ browse lớn each element in the array and proceed khổng lồ 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 to lớn enter multiple arrays, and output multiple times, Meanwhile let"s put on a function for easy entry và use.

See more: Đại Từ Xưng Hô Trong Tiếng Anh : Phân Loại Và Cách Dùng, Đại Từ Nhân Xưng Trong Tiếng Anh

// e.g about array - code by nguyenvanquan7826#include void nhapMang(int a<>, int n) { int i; // thuc hien nhap tung phan tu với for (i = 0; i Noted: An array of relationships with 1 pointer, array so as 1 pointer to the array passed to 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 to declare & 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 & 10 post (each row 10 element).

See more: So Sánh Ip6S Và Ip6 Plus : Cùng Mức Giá Nên Chọn Loại Nào? Nên Mua Iphone 6S Hay Iphone 6 Plus


Organization, storage array 2 way in C


Enter into lớn an array, find the biggest và 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 sầu 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 inkhổng lồ a matrix (Plate 2 evening). Print out the sum of each row of the matrix.

Chuyên mục: Blog