C File =>
/* Write a program to compute sum and average of all elements in an array using pointer */
#include<stdio.h>
int main() {
int num[30],n,i,sum;
float avg;
//declaring pointer to array
int (*p)[30]=#
printf("\n Enter how many elements :");
scanf("%d",&n);
printf("\n Accepting data :\n");
for(i=0;i<n;i++)
{
printf("\n Enter number%d:",i+1);
scanf("%d",&num[i]);
}
//calculating sum using pointer to array
for(i=0;i<n;i++)
sum=sum+(*p)[i];
avg=sum/n;
printf("\n Sum of array elements = %d\n Average=%f",sum,avg);
return 0;
}
Comments
Post a Comment
Please do not enter any spam link in message.