full code to write a C++ Program to find the Sum of the Series, 1 – x/2! + x^2/3! – x^3/4! + x^4/5! - …….. to n terms. Copy and paste to score good.
NOTE: E&OE, means errors and omissions are
expected and accepted, in other words, if
there is any error in the following article, the same has to be corrected by
the user or the beneficiary accordingly.
This article contains works derived from other reputed works of huge publication houses and notes
that were made by me in my school life.These articles are just to help people
who need these articles desperately and urgently. Any queries, complaints, and
corrections will be enthusiastically entertained.Write a C++ Program to find the Sum of the Series, 1 – x/2! + x^2/3! – x^3/4! + x^4/5! - …….. to n termsSum of 1 – x/2! + x^2/3! – x^3/4! + x^4/5! - …….. + n series in C++ Programming Language
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | #include<iostream> #include<math.h> using namespace std; int main() { int x, n; double s=0; cout<<"Enter the value of x:-"<<endl; cin>>x; cout<<endl<<"Enter the number of terms (n):-"<<endl; cin>>n; for( int i=0; i<=n;i++) { int f=1; for(int j=1;j<=(i+1);j++) { f=f*j; } s=s+pow(-1,(i+2))*(pow(x,i)/f); } cout<<"The value of the series stands - "<<s; return(0); } |
Code Sample 2 (for Turbo C++)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | #include<iostream,h> #include<math.h> void main() { clrscr(); int x, n; double s=0; cout<<"Enter the value of x:-"<<endl; cin>>x; cout<<endl<<"Enter the number of terms (n):-"<<endl; cin>>n; for( int i=0; i<=n;i++) { int f=1; for(int j=1;j<=(i+1);j++) { f=f*j; } s=s+pow(-1,(i+2))*(pow(x,i)/f); } cout<<"The value of the series stands - "<<s; getch(); } |
Sample Output:
Enter the x, i.e. the value of integer x which is in the series - 2
Enter the n i.e. max values
of series - 4
Sum of the series: 0.466667
Topic
covered here from class XI course is Programs on array manipulations (1D
& 2D).
___________________________________________________________________
Know
more about stuff related to this practical experiment (Important for Boards):-
- Viva Questions Array Manipulations.
- Difference between Dev C++ and Turbo C++.
- Difference between Dev C++ and CodeBlocks.
- Qualitative analysis for the identification of the functional group in the organic sample Acetic Acid (Example 1).
- How to find out the mass of salt required to achieve the required concentration of a solution
- Different types of Hydrocarbons
- Arora, Sumita. Computer Science with C++ for Class - 12
- Arora, Sumita. Computer Science with C++ for Class – 11
- C programming Interview questions and answers [http://www.cquestions.com/]
- The Crazy Programmer [http://www.thecrazyprogrammer.com]
For
latest syllabus, both theory and practical papers for class XII, check out the
CBSE’s official site http://cbseacademic.in/ for more info.
For more awesome coding and programs related to this language log onto http://www.thecrazyprogrammer.com or https://www.w3schools.in/.
___________________________________________________________________
Related
Questions-
Loop
Based program code
Loops for
while
Array manipulations
Header
files
Dev c++
Turbo C++
CodeBlocks
CBSE
class 12 computer science practicals
CBSE
class XII computer science practicals
Benzoic
AcidAptitude Amplifier ©2017. All Rights Reserved.