60 430
Assignments Done
98,1%
Successfully Done
In April 2018

Answer to Question #20843 in C++ for Piya

Question #20843
Write a program in c++ to find the sum of 'n' terms of series_
1/!1-2/!2+3/!3-4/!4+.........
Expert's answer

#include <iostream>
#include <conio.h>
using namespace std;

double factorial(long n);
//main function
int main()
{
int n;
cout<<"Enter n= ";
cin>>n;
double sum=0;
for(int i=1;i<=n;i++){
if(i%2==0){
sum-=i/factorial(i+1);
}else{
sum+=i/factorial(i+1);
}
}
cout<<"Y= "<<sum;
getch();
return 0;
}
//find factorial
double factorial(long n){
if (n < 1)
return 0;
double product = 1;
for (int i = 1; i <= n; i++)
product *= i;
return product;
}

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!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions