Code Box
---------------------------------------
/*Program to enter multiple values using for loop and calculate sum of all numbers */
#include<stdio.h>
#include<conio.h>
void main()
{
int num,i,sum,val;
clrscr();
sum=0;
printf("\nEnter numbers you want to enter:");
scanf("%d",&num);
for(i=1;i<=num;i++)
{
printf("\nEnter %d value",i);
scanf("%d",&val);
sum=sum+val;
printf("\nSum is= %d",sum);
}
printf("\nTotal Sum= %d",sum);
getch();
}
---------------------------------------
/*Program to enter multiple values using for loop and calculate sum of all numbers */
#include<stdio.h>
#include<conio.h>
void main()
{
int num,i,sum,val;
clrscr();
sum=0;
printf("\nEnter numbers you want to enter:");
scanf("%d",&num);
for(i=1;i<=num;i++)
{
printf("\nEnter %d value",i);
scanf("%d",&val);
sum=sum+val;
printf("\nSum is= %d",sum);
}
printf("\nTotal Sum= %d",sum);
getch();
}
No comments:
Post a Comment