Program to reverse the array elements:

C program to read elements into array and display:
int main () { int arr[5], i; printf(“Enter 5 elements : \n”); for(i=0 ; i<5 ; i++){ scanf(“%d”, &arr[i]); } printf(“Array elements are : \n”); for(i=0 ; i<5 ; i++){ printf(“%d \n”, arr[i]); } return 0; } |
C program to display array elements in reverse order:
int main () { int arr[5] = {10, 20, 30, 40, 50}, i; printf(“Reverse Array : \n”); for(i=4 ; i>=0 ; i–){ printf(“%d \n”, arr[i]); } return 0; } |
C Program to find sum of array elements:
int main () { int arr[5] = {10, 20, 30, 40, 50}, i, sum=0; for(i=0 ; i<5 ; i++){ sum = sum + arr[i]; } printf(“Sum of Array elements : %d \n”, sum); return 0; } |
C Program to find average of array elements:
int main () { int arr[5] = {10, 20, 30, 40, 50}, i, sum=0, avg; for(i=0 ; i<5 ; i++){ sum = sum + arr[i]; } printf(“Sum of Array elements : %d \n”, sum); avg = sum/5; printf(“Average of array elements : %d \n”, avg); return 0; } |
C Program to display only even numbers in the array:
int main () { int arr[8] = {8, 5, 1, 7, 4, 3, 2, 9}, i; printf(“Even numbers of Array : \n”); for(i=0 ; i<8 ; i++){ if(arr[i]%2==0) printf(“%d \t”, arr[i]); } return 0; } |
C program to display the largest element in the array:
int main() { int arr[8] = {7,2,9,14,3,27,5,4}; int large=arr[0], i; for(i=1 ; i<8 ; i++){ if(arr[i]>large) large = arr[i]; } printf(“Largest element is : %d \n”, large); return 0; } |