Sample – Program to enter an integer and print its total value based on the formula ‘x – 1/3!x3 + 1/5!x5 – 1/7!x7 + 1/9!x9′.

by Nideesh C on February 8, 2011 · 0 comments

in C++




#include <iostream.h>
#include <conio.h>
#include <math.h>
int main()
{
clrscr();
float factorial=1;
float num,tot,term,total;
int i,n=20,index,j=1;
cout << “Enter a single-digit integer : \n”;
cin>>num;
tot=num;
total=num;
for(i=2,index=3;i<=n;i++,index+=2)
{
for(j=1,factorial=1;j<=index;j++)
factorial*=j;
tot=tot*pow((double)(-1),(double)(2*i-1))*num*num;
term=tot/factorial;
total+=term;
}
cout << “Total = ” << total << endl;
getch();
return 0;
}

This program takes in an integer num as a screen input from the user.
It then calculates the total value of the integer based on the formula x – 1/3!x^3 + 1/5!x^5 – 1/7!x^7 + 1/9!x^9.
It then outputs the final answer using the ‘cout’ command.

Not Satisfied ? Just search & get the result

Related Posts Plugin for WordPress, Blogger...
Be Sociable, Share!

Related posts:

  1. Sample – Program to enter an integer and print out its successor.
  2. Sample – Program to enter an integer and output the cube of that integer.
  3. Sample – Program to enter an integer and find out if it is even or odd.
  4. Sample – Program to enter an integer and output its 15 multiples.
  5. Sample – Program to enter three integers and output the biggest integer using IF

Leave a Comment

Previous post:

Next post: