#include<stdio.h>
void read(int a[50],int n);
void display(int a[50],int n);
int sum(int a[50],int n);
int main()
{
int n,a[50],element,sum_array;
printf("Enter the size of the array\n");
scanf("%d",&n);
printf("Enter the array elements \n");
read(a,n);
printf("The array elements are\n");
display(a,n);
sum_array=sum(a,n);
printf("\nThe sum of array elements is : %d",sum_array);
}
void read(int a[50],int n)
{
int i;
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
}
void display(int a[50],int n)
{
int i;
for(i=0;i<n;i++)
{
printf("%d\t",a[i]);
}
}
int sum(int a[50],int n)
{
int i,sum=0;
for(i=0;i<n;i++)
{
sum=sum+a[i];
}
return sum;
}
Output:
Comments
Post a Comment