Write a program in c using for loop / statement , to enter 5 integer values and to print their sum
#include< #include< #include< main() { int i, x, sum; sum = 0; for ( i = 1; i < 5; i = i+1) { printf("Enter the value of x \n"); scanf("%d", &x); sum = sum + x; } printf("The sum is %d \n", sum); return(0); } |
---|
Output:-
Enter the value of x
10
Enter the value of x
20
Enter the value of x
30
Enter the value of x
40
Enter the value of x
50
The sum is 150
0 comments:
Post a Comment