c program to add n numbers
This c program add n numbers which will be entered by the user. Firstly user will enter a number indicating how many numbers user wishes to add and then user will enter n numbers.In our c program to add numbers we are not using an array, if you wish you can use an array.
Add n numbers.
Output:
C programming code
#include<stdio.h> #include<conio.h> main() { int n, sum = 0, c, var; printf("Enter the number of integers you want to add\n"); scanf("%d",&n); printf("Enter %d numbers\n",n); for ( c = 1 ; c <= n ; c++ ) { scanf("%d",&var); sum = sum + var; } printf("Sum of entered numbers = %d\n",sum); getch(); return 0; }
Add n numbers.
Output:
No comments:
Post a Comment