# C TUTORIAL
# C PROGRAMS
Pointers Examples
➤ Pointer Basic Examples
➤ Dynamic Memory Allocation
➤ Read Write Array with Pointer
➤ Sum Avg of Array with Pointer
➤ Sort Array with Pointer
➤ Search in Array using Pointer
➤ Sum of N Numbers
➤ Largest Number by DMA
Others
➤ C Program Without Main()
➤ Hello World Without ;
➤ Process & Parent Process ID
➤ C Program Without Header File
➤ void main(), main() vs int main()
➤ fork() function in C
➤ Why gets function is dangerous
➤ Undefined reference to sqrt
# C PROGRAMS
Pointers Examples
➤ Pointer Basic Examples
➤ Dynamic Memory Allocation
➤ Read Write Array with Pointer
➤ Sum Avg of Array with Pointer
➤ Sort Array with Pointer
➤ Search in Array using Pointer
➤ Sum of N Numbers
➤ Largest Number by DMA
Others
➤ C Program Without Main()
➤ Hello World Without ;
➤ Process & Parent Process ID
➤ C Program Without Header File
➤ void main(), main() vs int main()
➤ fork() function in C
➤ Why gets function is dangerous
➤ Undefined reference to sqrt
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[5], sum=0.0, avg;
int i;
float *px, *psum, *pavg;
px = &x[0]; // 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 do you find anything incorrect? Let us know in the comments. Thank you!
Similar C programs on Pointers