Hàm nhập mảng trong c


1. For example, the opening

Consider the example entry 5 integer, output to the screen 5 Among them on a line & total 5 which.

Bạn đang xem: Hàm nhập 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 & we made some screen seems very hard và 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. Lớn remedy this we use the array.

A mix of array elements with the same type of data. Array of arrays 1 evening, 2 evening,... Và 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 teo n phan tu int n = 5, i, s = 0; int a; // thuc hien nhap tung phan tu mang 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 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 1 array looks like this:


Retrieve array in C

2.4 How lớn import and 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 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 array using function

In many problem, we have khổng lồ enter multiple arrays, and output multiple times, Meanwhile let"s put on a function for easy entry & use.

Xem thêm: Hướng Dẫn Soạn Bài Cuộc Chia Tay Của Những Con Búp Bê Ngữ Văn 7 Tập 1

// 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 to lớn 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 khổng lồ 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 và 10 post (each row 10 element).

Xem thêm: Giải Địa Lí 7 Bài 20: Hoạt Động Kinh Tế Của Con Người Ở Hoang Mạc


Organization, storage array 2 way in C


Enter into 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 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.