Showing posts with label sum. Show all posts
Showing posts with label sum. Show all posts
Wednesday, February 18, 2015
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<<"
Enter the value of x and n:";
cin>>x>>n;
for(i=1;i<=n;++i)
sum+=pow(x,i);
cout<<"
Sum="<<sum;
getch(); //to stop the screen
}
Tuesday, February 17, 2015
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("
Enter the value of x and n:");
scanf("%f%d",&x,&n);
for(i=1;i<=n;++i)
sum+=pow(x,i);
sum++;
printf("
Sum=%f",sum);
getch(); //to stop the screen
}
Subscribe to:
Posts (Atom)