Write a program to find sum of 10 numbers
Answers
Answered by
0
Here are two ways of doing so —
Using while loop
main()
{
int sum = 0;
int n = 10;
while(n--)
{
int x;
scanf("%d", &x);
sum = sum + x;
}
printf("%d", sum);
}
Here , while loop has been used instead of using array .
While loop gets executed 10 times to take input .
2. Using goto command
main()
{
int i = 1, sum = 0;
input:
int x;
scanf("%d",&x);
i ++;
sum = sum + x;
if(i <= 10)
goto input;
printf("%d",sum);
}
Anshul Asawa
Answered April 25, 2018
#include<stdio.h>
#include<stdlib.h>
int main()
{
int sum=0,num;
printf("Enter 10 numbers : ");
for(int i=0;i<10;i++)
{
scanf("%d",&num);
sum+=num;
}
printf("Sum = %d",sum);
}
Similar questions