84 350
Assignments Done
98,8%
Successfully Done
In March 2020

# Answer to Question #45007 in C++ for nilesh

Question #45007
1.write a proram to find the sum of series a)S=1+x+x^2+x^3......................+x^n b)1^2+2^2+3^2..............+n^2 c)2/9-5/13+8/17.................. 2.to print fibonacci series.
1
2014-08-25T07:15:26-0400
#include <stdlib.h>
#include <iostream> // for cout and cin
#include <stdio.h>
#include <cstdlib> // for system
using namespace std;
long Power(long x, long _power)
{
long _x = x;
if (_power == 0) return 1;
for (long i = 0; i < _power -1;i++)
x *= _x;
return x;

}
int main()
{
long Sum1 = 0; long Sum2 = 0;
double value = 0;
double Sum3 = 0;
long x = 0; long n = 0;
cout<<"enter n"<<endl;
cin>>n;
cout<<"enter x"<<endl;
cin>>x;
for (long i = 0; i < n + 1; i++)
{
Sum1 += Power( x, i);
Sum2 += Power( i, 2);
if (i < n)
{
value = (2 + i*3)/ double(9 + i*4);
if (i % 2 != 0) value *= -1;
Sum3 += value;
}
}
cout<<"Sum1 = "<<Sum1<<endl;
cout<<"Sum2 = "<<Sum2<<endl;
cout<<"Sum3 = "<<Sum3<<endl;
system("pause");
return 0;
}

#include <stdlib.h>
#include <iostream> // for cout and cin
#include <stdio.h>
#include <cstdlib> // for system
using namespace std;
long Fibon(long i)
{
if(i==0) return 1;
if(i==1) return 1;
if(i<0) return 0;
return Fibon(i-2) + Fibon(i-1);
}
int main()
{
long value,n;

cout<<"How many Fibonacci numbers do you want to display?"<< endl;
cin>>n;
cout<<endl;
cout<<"Fibonacci numbers : ";
for (int i = 0; i < n ; i++)
{
value = Fibon(i);
cout<<value<<" ";
}
cout<<endl;
system("pause");
return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!