sahajjain01

24.Find average of the elements of an array.

Sep 29th, 2015
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.33 KB | None | 0 0
  1. //Program to find average of the elements of an array.
  2. #include<stdio.h>
  3. #include<conio.h>
  4.  
  5. void main() {
  6.  
  7.     int arr[5] = {2, 4, 7, 9, 8};
  8.     int i = 0;
  9.     float avg = 0;
  10.  
  11.     clrscr();
  12.  
  13.     for(i = 0; i < 5; i++)
  14.         avg = avg + arr[i];
  15.  
  16.     avg = avg / i;
  17.     printf("The average of the elements of the array is: %f", avg);
  18.  
  19.     getch();
  20. }
Advertisement
Add Comment
Please, Sign In to add comment