# Sum of Series

## Java program to find sum of harmonic series 1 + 1/2 + 1/3 + 1/4 + 1/5 +……+ 1/n

class Harmonic { public static void main(String…s) { int n,i; float sum=0; n=Integer.parseInt(s[0]); for(i=1;i<=n;i++) { sum=sum+(float)1/i; } System.out.println(“nSum=”+sum); } }

## C++ program to find sum of series 1+1/2^2+1/3^3+…..+1/n^n

#include<iostream.h> #include<conio.h> #include<math.h> void main() { clrscr(); double sum=0,a; int n,i; cout<<“1+1/2^2+1/3^3+…..+1/n^n”; cout<<“nEnter value of n:”; cin>>n; for(i=1;i<=n;++i) { a=1/pow(i,i); sum+=a; } cout<<“Sum=”<<sum; getch(); }

## C program to find the sum of series 1/2+4/5+7/8+……

#include<stdio.h> #include<conio.h> void main() { int i,n; clrscr(); float sum=0,x,a=1; printf(“1/2+4/5+7/8+……”); printf(“nnHow many terms(ex: 1,2,3…n)?”); scanf(“%d”,&n); for(i=0;i<n;++i) { x=a/(a+1); sum+=x; a+=3; } printf(“nSum=%f”,sum); getch(); }

## C++ program to find sum of series 1 + 2 + 3 +……+ n

#include<iostream.h> #include<conio.h> void main() { clrscr(); int i,n,sum=0; cout<<“1+2+3+……+n”; cout<<“nEnter the value of n:”; cin>>n; for(i=1;i<=n;++i) sum+=i; cout<<“nSum=”<<sum; getch(); }

## C program to find the sum of the series x+x^2/2+x^3/3+…..+x^n/n

#include<stdio.h>#include<conio.h>#include<math.h>void main(){ int i,n; float x,sum=0; clrscr(); //to clear the screen printf(“x+x^2/2+x^3/3+…..+x^n/n”); printf(“nEnter value of x and n:”); scanf(“%f%d”,&x,&n); for(i=1;i<=n;++i) sum+=pow(x,i)/i; printf(“nsum=%f”,sum); getch(); //to stop the screen}

## C++ program to find the sum of the series x+x^2/2+x^3/3+…..+x^n/n

#include<iostream.h>#include<conio.h>#include<math.h>void main(){ clrscr(); //to clear the screen int i,n; float x,sum=0; cout<<“x+x^2/2+x^3/3+…..+x^n/n”; cout<<“nEnter value of x and n:”; cin>>x>>n; for(i=1;i<=n;++i) sum+=pow(x,i)/i; cout<<“nsum=”<<sum; getch(); //to stop the screen}

## C program to find sum of series 1+x+x^2+……+x^n

#include<stdio.h>#include<conio.h>#include<math.h>void main(){ int i,n; float x,sum=0; clrscr(); //to clear the screen printf(“1+x+x^2+……+x^n”); printf(“nnEnter the value of x and n:”); scanf(“%f%d”,&x,&n); for(i=1;i<=n;++i) sum+=pow(x,i); sum++; printf(“nSum=%f”,sum); getch(); //to stop the screen}

## C++ program to find sum of series 1/2+4/5+7/8+……

#include<iostream.h>#include<conio.h> void main(){ clrscr(); //to clrscr the screen int i,n; float sum=0,x,a=1; cout<<“1/2+4/5+7/8+……”; cout<<“nnHow many terms(ex: 1,2,3…n)?”; cin>>n; for(i=0;i<n;++i) { x=a/(a+1); sum+=x; a+=3; } cout<<“nSum=”<<sum; getch(); //to stop the screen}