Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*Write a program to take some numbers into an array
- and calculate the sum and average of the array elements.*/
- #include<stdio.h>
- int main()
- {
- int sum = 0;
- float avg;
- int ar[] = {1,6,3,7,8,4,3,6};
- int n = sizeof(ar)/sizeof(ar[0]);
- for (int i = 0; i < n; ++i)
- sum += ar[i];
- avg = sum/(float)n;
- printf("Sum: %d\nAverage: %f\n", sum, avg);
- return 0;
- }
Add Comment
Please, Sign In to add comment