An array is a fixed size sequenced collection of elements of the same data type.
Examples:
type array-name[size];
int status[10];
char message[15];
float marks[15];
Note:
type array-name[size] = { list of values };
Initialization can be done at compile time or at run time
If the array is not initialized then it will have garbage values.
int status[3] = { 1, 2, 3 };
char message[5] = {'a','e','i','o','u'};
float marks[4] = { 4.5, 5.6, 7.1, 3.3 };
Note:
Size can be ommited. It will be computed from the number of elements in the initialization.
int status[] = { 1, 2, 3 }; // size is 3
char message[] = {'a','e','i','o','u'}; // size is 5
float marks[] = { 4.5, 5.6, 7.1, 3.3 }; // size is 4
Note:
Compile time initialization can be partial. That is the number of initializers can be less than the declared size. In such cases the remaining elements are initialized with zero for numeric type and to NULL ($ \0 $) for char type
int status[3] = { 1 }; // 1 , 0 , 0
char message[5] = {'a','e' }; // 'a','e','\0','\0','\0'
float marks[4] = { 4.5, 5.6, 7.1 }; // 4.5 , 5.6 , 7.1 , 0
Write a program to record the hourly temperatures using arrays and find the mean temperature.
Write a program to compute the sum of elements of two one dimensional arrays and store it in a new one dimensional array.
An election is contested by five candidates. The candidates are numbered 1 to 5 and the voting is done by marking the candidate number in ballot paper. WAP to read the ballot paper and count the votes. The program should declare the winner of maximum votes. If the number is outside the range then it should take it as spoilt ballot and also count the number of such spoilt ballot.
type array-name[row-size][column-size];
int students[5][5];
char message[15][10];
float marks[15][2];
Array to store the marks of five students - One Dimensional
int marks[5];
Array to store the marks of five students in five subjects- Two Dimensional
int marks[5][5];
// 5 students x 5 subjects or 5 Subjects x 5 Students
To store votes of ten candidates - One Dimensional
int votes[10];
To store votes of 10 parties in 5 states - Two Dimensional
int votes[10][5]; // 10 Parties x 5 States
int votes[5][10]; // 5 States x 10 Parties
type array-name[row][column] = { list of values };
int status[3][2] = { 1, 1, 2, 2, 3, 3 };
int status[3][2] = { {1, 1}, {2, 2}, {3, 3} };
int status[3][2] = {
{1, 1},
{2, 2},
{3, 3}
};
The array initialization is done row by row.
Partial initialization is possible.
The value inside the sqare brackets are called Array Subscripts. They should be integer.
![]() |
![]() |
WAP to find the transpose of a 3x3 matrix.
WAP to do matrix addition.
WAP to do matrix multiplication.
Write a program in C to count a total number of duplicate elements in an array.
Write a program in C to print all unique elements in an array.
Write a program in C to find the maximum and minimum element in an array.
Write a program in C to sort elements of array in ascending order.