BZU PAGES: Find Presentations, Reports, Student's Assignments and Daily Discussion; Bahauddin Zakariya University Multan Right Header

HOME BZU Mail Box Online Games Radio and TV Cricket All Albums
Go Back   BZU PAGES: Find Presentations, Reports, Student's Assignments and Daily Discussion; Bahauddin Zakariya University Multan > Institute of Computing > Bachelor of Science in Information Technology > BsIT 2nd Semester > Object Oriented Programming


Reply
 
Thread Tools Search this Thread Rate Thread Display Modes
  #1  
Old 28-02-2011, 10:58 PM
bonfire's Avatar
M.Arsalan Qureshi

 
Join Date: Oct 2008
Location: Garden Town, Multan Cantt
Posts: 616
Program / Discipline: BSTS
Class Roll Number: 09-31
bonfire has a reputation beyond reputebonfire has a reputation beyond reputebonfire has a reputation beyond reputebonfire has a reputation beyond reputebonfire has a reputation beyond reputebonfire has a reputation beyond reputebonfire has a reputation beyond reputebonfire has a reputation beyond reputebonfire has a reputation beyond reputebonfire has a reputation beyond reputebonfire has a reputation beyond repute
Default Program to enter an integer and print its total value based on the formula 'x - 1/3!x^3 + 1/5!x^5 - 1/7!x^7 + 1/9!x^9'

Program to enter an integer and print its total value based on the formula
'x - 1/3!x^3 + 1/5!x^5 - 1/7!x^7 + 1/9!x^9'

#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.

Sample Input
3 Sample Output
Total = 0.14112
__________________

Reply With Quote
Reply

Tags
1 or 3x3, 1 or 5x5, 1 or 7x7, 1 or 9x9, based, enter, formula, integer, print, program, total


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Program to enter an integer and print if it is prime or composite bonfire Object Oriented Programming 1 22-11-2011 07:45 PM
Program to enter an integer and print out its successor bonfire Object Oriented Programming 0 01-03-2011 02:55 PM
Program to enter an integer and output the cube of that integer bonfire Object Oriented Programming 0 01-03-2011 02:53 PM
Program to enter an integer and print if it is greater or less than 100 bonfire Object Oriented Programming 0 01-03-2011 02:28 PM

Best view in Firefox
Almuslimeen.info | BZU Multan | Dedicated server hosting
Note: All trademarks and copyrights held by respective owners. We will take action against any copyright violation if it is proved to us.

All times are GMT +5. The time now is 11:15 AM.
Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.