### Array Programming in C

Write a program to calculate sum and average of all numbers from an Array(a[10])

1. #include
main()
{
printf("Enter the array size :");
int i,n,sum=0;
float avg;
scanf ("%d",&n);
int a[n];
printf("Enter the values :\n");
for (i=0;i<n;i++)
scanf ("%d",&a[i]);
for (i=0;i<n;i++)
sum+=a[i];
printf("\nThe sum is : %d",sum);
avg=(float)sum/n;
printf("\nThe avarege of all : %f",avg);
}

2. #include
#include
int *funcx(int p[],int size);
int main()
{
int a[10];
int (*pFn)(int ,int),ptr;
pFn=funcx;
ptr=(*pFn)(a,10);
printf("\n Average is %f",(float)ptr);
getch();
return 0;

}

int *funcx(int p[],int size)
{
int i,sum=0,n;
int average;
printf("\n Enter array value");
for(i=0;i<size;i++)
{
scanf("\n%d",&p[i]);
sum+=p[i];

}
printf("\n The sum is %d",sum);
average =(int)(sum)/10;

return average;
}

3. #include
#include
int *pori(int p[],int size);
int main()
{
int a[10] ;
int (*nilpori)(int q ,int w),ptr;
nilpori=pori;
ptr=(*nilpori)(a,10);
printf("\n Average is %f",(float)ptr);
getch();
return 0;
}
int *pori(int p[],int size)
{
int i,sum=0,n;
int ave;
printf("\n Enter array value");
for(i=0;i<size;i++)
{
scanf("\n%d",&p[i]);
sum+=p[i];
}
printf("\n The sum is %d",sum);
ave =(int)(sum)/10;
return ave;
}

4. #include
main()
{
printf("Enter the array size :");
int i,n,sum=0;
float avg;
scanf ("%d",&n);
int a[n];
printf("Enter the values :\n");
for (i=0;i<n;i++)
scanf ("%d",&a[i]);
for (i=0;i<n;i++)
sum+=a[i];
printf("\nThe sum is : %d",sum);
avg=(float)sum/n;
printf("\nThe avarege of all : %f",avg);
}

5. #include
main()
{
printf("Enter the array size :");
int i,j,sum=0;
float avg=0;
scanf("%d",&j);
int a[j];
printf("Enter the values :\n");
for (i=0;i<j;i++)
scanf("%d",&a[i]);
for (i=0;i<j;i++)
{
sum+=a[i];
}
printf("\nThe sum is : %d",sum);
avg=(float)sum/j;
printf("\nThe avarege of all : %f",avg);
}

6. This comment has been removed by the author.