Write a C program to sum the series
1 + (1+2) + (1+2+3) + (1+2+3+4) + (1+2+......+ N) for a given integer N.
#include<stdio.h> #include<conio.h> void main() { int i,sum=1,j,n; printf("Enter a number:-"); scanf("%d",&n); printf(" 1 +"); for(i=2;i<=n;i++) { printf(" ("); for(j=1;j<=i;j++) { sum+=j; if(j==i) printf(" %d ",j); else printf(" %d +",j); } if(i==n) printf(" )"); else printf(" ) +"); } printf(" Sum =%d",sum); getch(); }Output:-
0 Comments