Sum of Series

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

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

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

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