 # Category: Arrays and Structures

Write a program in C that accepts number of array elements from the user, accepts array element values and calculates the sum/addition of all the array elements. The program should display the value of addition. #include<stdio.h> int main() { int arr, i, no,sum=0; clrscr(); printf(“\nEnter the no. of elements: “); scanf(“%d”,&no); for(i=0;i<no;i++) { printf(“\nEnter element %d”,i+1); scanf(“%d”, &arr[i]); } for(i=0;i<no;i++) { sum=sum+arr[i]; } printf(“\nsum of array element: %d”,sum); return 0; } Output: Enter the no. of elements: 5 Enter element 1 : 1 Enter element 2 : 2 Enter element 3 : 3 Enter element 4 : 4 Enter element...

## 2-Dimensional (2D) Array in C Programming Language

An array is a collective name given to a group of similar variables. An array can be 1-Dimensional, 2-Dimensional, 3-Dimensional and so on. In this topic, we will discuss 2-Dimensional (2D) arrays in C Programming Language. Let us understand what two dimensional arrays are. Consider the following matrix. 11 12 13 A= 14 15 16 17 18 19 The above-mentioned matrix is 3 by 3. The matrix elements can be accessed using the formula A[m,n], where m represents row number and n represents column number. Thus, the first element i.e. 11 is represented as A[0,0]. Similarly, A[0,1] = 12 A[0,2]...

## C Arrays – 1D (1 Dimensional)

An array in C is a collective name given to a group of similar variables. C arrays can be 1-Dimensional, 2-Dimensional, 3-Dimensional and so on. In this topic, we will discuss 1-Dimensional (1D) arrays in C. So lets start with 1D array in C. Let us understand C arrays with the help of an example. void main(){ int arr,i; printf(“Enter 3 values\n”); for(i=0;i<3;i++) { scanf(“%d”,&arr[i]) } printf(“The entered values are:\n”); for(i=0;i<10;i++) { printf(“%d\t”,arr[i]) } } Explanation: int arr statement declares an array capable of holding 3 integer values. The first value can be accessed using arr. Similarly second value can... 