Program for Sum of n numbers 1 + 2 + .... + n
# include<stdio.h> #include<conio.h> void main() { int n; printf ( “enter n value”); scanf ( "%d", &am...
https://www.computersprofessor.com/2016/06/program-for-sum-of-n-numbers-1-2-n.html
# include<stdio.h>
#include<conio.h>
void main()
{
int n;
printf ( “enter n value”);
scanf ( "%d", & n);
n = n * (n+1)/2;
printf ( “\n sum of n natural numbers is %d", n );
getch();
}
Out put :
enter n value 3
sum of n natural numbers is 6