# Find Sum and Average of an Array Using the Pointer in C

C Program to Find Sum and Average of an Array Using the Pointer. Take input from the end-user for the array of numbers, calculate sum and average. Later display those results to the screen. Use the pointer to perform all these operations. Here, we will develop a program to find sum and average of an array using the pointer in c.

``````#include<stdio.h>
int main()
{
float x, sum=0.0, avg;
int i;
float *px, *psum, *pavg;

px = &x;  //  Or, px = &x;
psum = &sum, pavg = &avg;

printf("Enter array Elements: ");
for (i=0;i<5;i++)
{
scanf("%f",(px+i));
*psum += *(px + i);
}

*pavg = *psum / 5;
printf("Sum= %.2f \t Average= %.2f\n", *psum, *pavg);

return 0;
}``````

Output:-

Enter array Elements: 10
24
30
62
15
Sum=141.00 Average=28.20

If you enjoyed this post, share it with your friends. Do you want to share more information about the topic discussed above or you find anything incorrect? Let us know in the comments. Thank you!

Similar C programs on Pointers