Mảng trong c

1. For example, the opening

Consider the example entry 5 integer, output đầu ra to the screen 5 Among them on a line và total 5 which.

Bạn đang xem: 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 và we had 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 lớn remedy this we use the array.

A set of array elements with the same type of data. Array of arrays 1 evening, 2 evening,... & 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() { // khai bao mang a co n phan tu int n = 5, i, s = 0; int a; // thuc hien nhap tung phan tu với 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 khổng lồ 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 lượt thích this:

*

Retrieve array in C

2.4 How to lớn import & 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 and proceed to 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 đầu ra array using function

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

Xem thêm: Chuyển Đổi Mp4 Sang Mp3 Trực Tuyến Miễn Phí ), Chuyển Đổi Mp4 Sang Mp3 Trực Tuyến

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

*

Organization, storage array 2 way in C

Exercise

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 & printed in ascending sequence.Entered into a matrix (Plate 2 evening). Print out the sum of each row of the matrix.