This program adds all the elements of array and print the sum and average of it using pointers and function. This is a part of Mumbai University MCA Colleges C program MCA Sem 1
#include<stdio.h>
#include<conio.h>
void add(int *, int);
void main()
{
int a[15],n,i,j;
clrscr();
printf("Enter no of elements you want to enter in array");
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
add(a,n);
getch();
}
void add(int *x , int y)
{
int i,sum=0;
float avg=0;
for(i=0;i<y;i++)
{
sum+=*(x+i);
}
avg=sum/y;
printf("\nSum of array= %d",sum);
printf("\nAverage of array elements = %f",avg);
}
Hope this Program is useful to you in some sense or other. Keep on following this blog for more Mumbai University MCA College Programs. Happy Programming and Studying.