Here are five C++ program to find sum of different series.
C++ program to find the sum of series: 1 + (1 + 2) +..+ (1 + 2 +..+ N)
#include<iostream>
using namespace std;
int main()
{
int temp=0,n;
cout<<"Enter the value of n ";
cin>>n;
for(int i=1;i<=n;i++)
{
for(int y=1;y<=i;y++)
{
temp+=y;
}
}
cout<<"Series: 1 + (1 + 2) +..+ (1 + 2 +..+ N) = "<<temp;
return 0;
}
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgKUwvidrloZ9CNYH-9SP8ve1kzMZ-0v4kbZNu8q_2XaR4b7tEL0a1Ld0FdxpRCO1Wy3PGenTdhzNjLc5VMmf7yknl8VrHrl94K91Rq_BwALljvaGXKKia89sQTy52sX3XU2gLP-cj_Gke9/s1600/Capture238.PNG)
using namespace std;
int main()
{
int temp=0,n;
cout<<"Enter the value of n ";
cin>>n;
for(int i=1;i<=n;i++)
{
for(int y=1;y<=i;y++)
{
temp+=y;
}
}
cout<<"Series: 1 + (1 + 2) +..+ (1 + 2 +..+ N) = "<<temp;
return 0;
}
OUTPUT
C++ program to evaluate the series 1 + 1/2 + 1/3 + .. + 1/N
#include<iostream>
using namespace std;
int main()
{
float temp=0,n;
cout<<"Enter the value of n ";
cin>>n;
for(int i=1;i<=n;i++)
{
temp+=1/(1.0*i);
}
cout<<"Series: 1 + 1/2 + 1/3 + .. + 1/N = "<<temp;
return 0;
}
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiII5B3QCsKbzeJAnqLh3_RAzSkBcfhBkt_y8xPJ0YoQGa1dLkcbh_A5kzVc4lj3DzuRe8rEmoUMa3sYz8ADGj47nDDGMbUpiUU7jCiXZjaJdENDczahXUk0KBwpkqiHYqGlVOS-koU-GLN/s1600/Capture239.PNG)
using namespace std;
int main()
{
float temp=0,n;
cout<<"Enter the value of n ";
cin>>n;
for(int i=1;i<=n;i++)
{
temp+=1/(1.0*i);
}
cout<<"Series: 1 + 1/2 + 1/3 + .. + 1/N = "<<temp;
return 0;
}
OUTPUT
C++ program to evaluate the series 1 + 1/3 + 1/5 + ...+1/x
#include<iostream>
using namespace std;
int main()
{
float temp=0,n;
cout<<"Enter the value of n ";
cin>>n;
for(int i=1;i<=n;i++)
{
if(i%2==1)
temp+=1/(1.0*i);
}
cout<<"Series: 1 + 1/3 + 1/5 + ...+1/x = "<<temp;
return 0;
}
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjxlCfNCnauLhYZz6ZJGHKgXN3pSbipu21jgb2EgeaoyLmNov1qZj2sWKN54SgyyFb5P-ZzOAywj4vYijTS0tRdIv3GGZpcJ0ck7JASvhbVRxzvVbAVrz3hQa7_cb8aRUVcwin4Zk4yf-Fl/s1600/Capture240.PNG)
using namespace std;
int main()
{
float temp=0,n;
cout<<"Enter the value of n ";
cin>>n;
for(int i=1;i<=n;i++)
{
if(i%2==1)
temp+=1/(1.0*i);
}
cout<<"Series: 1 + 1/3 + 1/5 + ...+1/x = "<<temp;
return 0;
}
OUTPUT
C++ program to evaluate the series 1 - 1/2 + 1/3 -1/4 + ...+1/x
#include<iostream>
using namespace std;
int main()
{
float temp=0,n,y=1;
cout<<"Enter the value of n ";
cin>>n;
for(int i=1;i<=n;i++)
{
temp+=y*(1/(1.0*i));
y=-y;
}
cout<<"Series: 1 - 1/2 + 1/3 -1/4 + ...+1/x = "<<temp;
return 0;
}
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiqnvj-yIECklxFrb_emY5JCPOH5L0xrUjVOXwABaNtB-xyA6Ewq6PgK7bVljtHSv6oMZ3t4_1uQX7kV-96rUK3D2fpEjzVRN_hM2386WMT46qU641b4L43o6Yx7p8kBhNkH-NT7VnG1nl-/s1600/Capture241.PNG)
using namespace std;
int main()
{
float temp=0,n,y=1;
cout<<"Enter the value of n ";
cin>>n;
for(int i=1;i<=n;i++)
{
temp+=y*(1/(1.0*i));
y=-y;
}
cout<<"Series: 1 - 1/2 + 1/3 -1/4 + ...+1/x = "<<temp;
return 0;
}
OUTPUT
C++ program to evaluate the series 1/1! + 2/2! + 3/3! +...+n/n!
#include<iostream>
using namespace std;
long factorial(int n)
{
long fact=1;
while(n>0)
{
fact*=n;
n--;
}
return fact;
}
int main()
{
float temp=0,n;
cout<<"Enter the value of n ";
cin>>n;
for(int i=1;i<=n;i++)
temp+=i/(1.0*factorial(i));
cout<<"Series: 1 + 2/2! + 3/3!+ ...+n/n! = "<<temp;
return 0;
}
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjbZalFgIJpTwovuDnILUE-v753b6vsrRjxzGuoLlAO2Uy_gZSen4KlZMb8YeuL5LLyfqJAhbWSuUM4vnXM6xrGzeWS3Hl8QN9oCr0Cde8_R73qO_lMxHaKFOuZuGaMxXL0S0YbkGMCV8Nl/s1600/Capture242.PNG)
using namespace std;
long factorial(int n)
{
long fact=1;
while(n>0)
{
fact*=n;
n--;
}
return fact;
}
int main()
{
float temp=0,n;
cout<<"Enter the value of n ";
cin>>n;
for(int i=1;i<=n;i++)
temp+=i/(1.0*factorial(i));
cout<<"Series: 1 + 2/2! + 3/3!+ ...+n/n! = "<<temp;
return 0;
}
OUTPUT
C++ program to evaluate the series 1 + 2*1 + 3*2 + 4*3 + 5*4 + ... N*N-1
#include<iostream>
using namespace std;
int main()
{
float temp=1,n;
cout<<"Enter the value of n ";
cin>>n;
for(int i=1;i<=n;i++)
temp+=i*(i-1);
cout<<"Series: 1 + 2*1 + 3*2 + 4*3 + 5*4 + ... N*N-1 = "<<temp;
return 0;
}
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiB6QDEM5Z6lkDSSeT86smb0emRO_10W4jbGHqXzhv6M9vG1HnmkfKkO7l7ZLjBi1_ADRro2Wk3iaDijYOgT9esuOrU353qZa6jQcKNBTgQAs45g9j0RtYchoyWtdC6BMxHNAVapHEHEsVp/s1600/Capture243.PNG)
using namespace std;
int main()
{
float temp=1,n;
cout<<"Enter the value of n ";
cin>>n;
for(int i=1;i<=n;i++)
temp+=i*(i-1);
cout<<"Series: 1 + 2*1 + 3*2 + 4*3 + 5*4 + ... N*N-1 = "<<temp;
return 0;
}
No comments:
Post a Comment