C program to find sum of n numbers:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
#include <stdio.h> int main() { int num, sum = 0, count, i; printf("Please enter how many numbers you want to add\n"); scanf("%d", &num); printf("Please enter %d numbers one by one\n",num); for (count = 1; count <= num; count++) { scanf("%d",&i); sum = sum + i; } printf("Sum of entered numbers = %d\n",sum); return 0; } |
Please enter how many numbers you want to add
3
Please enter 3 numbers one by one
40
20
10
Sum of entered numbers = 70