Program
ADDITION OF THE ELEMENTS OF THE LIST
#include<stdio.h>
#include<conio.h>
void main()
{
void read(int *,int);
void dis(int *,int);
int a[5],i,sum=0;
clrscr();
printf("Enter the elements of list \n");
read(a,5); /*read the list*/
printf("The list elements are \n");
dis(a,5);
for(i=0;i<5;i++)
{
sum+=a[i];
}
printf("The sum of the elements of the list is %d\n",sum);
getch();
}
void read(int c[],int i)
{
int j;
for(j=0;j<i;j++)
scanf("%d",&c[j]);
fflush(stdin);
}
void dis(int d[],int i)
{
int j;
for(j=0;j<i;j++)
printf("%d ",d[j]);
printf("\n");
}
Example
Input
Enter the elements of the first array15
30
45
60
75
Output
The elements of the first array are15 30 45 60 75
The sum of the elements of an array is 225.
No comments:
Post a Comment