Write a program that displays sum of all given array numbers.
Given array numbers are: 100,150,-170,240,120
source file name: Arraysum.C
void main()
{
int S[]={100,150,-170,240,120};
int i,sum=0;
clrscr();
printf("\nArray numbers are: ");
for(i=0;i<5;i++)
{
printf(" %d ",S[i]);
}
printf("\n Sum of all array numbers: ");
for(i=0;i<5;i++)
{
sum=sum+S[i];
}
printf("\n %d ",sum);
getch();
}
output:
Array numbers are:
100 150 -170 240 120
Sum of all array numbers:
440
0 Comments
Post a Comment