ibrahim_065

1.Write a program to take some numbers into an array and calculate the sum and average of the array elements.

Aug 13th, 2020 (edited)
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.36 KB | None | 0 0
  1. /*Write a program to take some numbers into an array
  2. and calculate the sum and average of the array elements.*/
  3. #include<stdio.h>
  4. int main()
  5. {
  6.     int sum = 0;
  7.     float avg;
  8.     int ar[] = {1,6,3,7,8,4,3,6};
  9.     int n = sizeof(ar)/sizeof(ar[0]);
  10.     for (int i = 0; i < n; ++i)
  11.         sum += ar[i];
  12.     avg = sum/(float)n;
  13.     printf("Sum: %d\nAverage: %f\n", sum, avg);
  14.     return 0;
  15. }
Add Comment
Please, Sign In to add comment