Write a program in c using while loop / statement , to enter 5 integer values and to print their sum
#include< #include< #include< main() { int i, x, sum; sum = 0; i = 1; while ( i < = 5) { printf("Enter the value of x \n"); scanf("%d", &x); sum = sum + x; i = i + 1; } 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