Sum of series S=1+(1+2)+(1+2+3)+..….+(1+2+3+…+n)
Write a C program to find Sum of series S=1+(1+2)+(1+2+3)+..….+(1+2+3+…+n).This program calculates the sum of series upto n i.e user input and produce result.
In this C Program, Firstly we are going to take input integer ‘n’ from the user and then starts loops starting from 1 to n and calculate sum for each iteration.After that just print the result i.e sum as output on the screen.
Here, the C program to find Sum of series S=1+(1+2)+(1+2+3)+..….+(1+2+3+…+n) is successfully compiled and run on the windows system and produces the output as shown below for different input i.e n. Let’s check out this C Program shown below : :
SOURCE CODE : :
/* C program to find Sum of series S=1+(1+2)+(1+2+3)+..….+(1+2+3+…+n) */ #include<stdio.h> int main() { int n,sum,sum1=0,i,j; printf("\nEnter value for n = "); scanf("%d",&n); for(i=1;i<=n;i++) { sum=0; for(j=1;j<=i;j++) { sum=sum+j; } sum1=sum1+sum; } printf("\nThe Sum of Series up to Value [ %d ] = [ %d ]\n",n,sum1); return 0; }
OUTPUT : :
/* C program to find Sum of series S=1+(1+2)+(1+2+3)+..….+(1+2+3+…+n) */ Enter value for n = 10 The Sum of Series up to Value [ 10 ] = [ 220 ] Process returned 0
Above is the source code for C program to find Sum of series S=1+(1+2)+(1+2+3)+..….+(1+2+3+…+n) which is successfully compiled and run on Windows System.The Output of the program is shown above .
If you found any error or any queries related to the above program or any questions or reviews , you wanna to ask from us ,you may Contact Us through our contact Page or you can also comment below in the comment section.We will try our best to reach up to you in short interval.
Thanks for reading the post….
Can you explain the program
pls explain the program
/! You can use one loop to do it
using namespace std;
#include
int main()
{
int i,n,s,ts;
s=ts=0;
cin>>n;
for(i=1;i<=n;i++)
{
s=s+i;
ts=ts+s;
}
cout<<ts;
}