C program to print sum of series 1+2+3+..+n
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
#include<stdio.h> void main() { int sum=0,i,n; printf("\n>>> C Program to print Sum of Series 1+2+3+..+n <<<\n"); printf("\n Enter the number of terms:"); scanf("%d",&n); for(i=1;i<=n;i++) { sum+=i; } printf("\n Sum of series upto %d is :%d \n\n",n,sum); } |
Sample Output: