I am going to explain in this post that how to calculate sum of five number using integer type array.
void main()
{
int a[5],i,sum=0;
printf("Enter 5 number");
for(i=0;i<5;i++)
{
printf("Enter %d number:",i+1);
scanf(&a[i],"%d");
}
for(i=0;i<5;i++)
sum=sum+a[i];
printf("Sum=%d",sum);
getch();
}
void main()
{
int a[5],i,sum=0;
printf("Enter 5 number");
for(i=0;i<5;i++)
{
printf("Enter %d number:",i+1);
scanf(&a[i],"%d");
}
for(i=0;i<5;i++)
sum=sum+a[i];
printf("Sum=%d",sum);
getch();
}
No comments:
Post a Comment