hi every body

i need a lot of help in my assignment :

and of course i will show my work .

really biggeners
:confused:

+++++++++++++++++++++++++++++++++++++++++++++++

+++++++++++++++++++++++++++++++++++++++++++++++

this is the task :
The factorial of a number n (written n!) is the number times the factorial of itself minus one; and
the factorial of 1 is, by definition, equal to 1. For example the factorial of 2 is 2*1! = 2*1, and
the factorial of 3 is 3*2!= 3*2*1=6, and so on. Implementing this definition using a computer
program is relatively slow, instead Sterling’s formula is used as an approximation of the factorial
for large values. Sterling’s formula is defined as follows:

( the formula is down in attachment )

The exp function in the <cmath> header file gives the value of e raised to a given power

Write a C++ program that asks the user to enter 5 large values of n ( > 10), calculates their factorial using sterling’s formula and displays the results in a tabular format.

The results should be displayed two times:

1. The first time use scientific representation and default precision.

2. The second time use a non-scientific representation and 2-decimal precision.

Please note that π=22.0/7.


==============================


i will write what i already did

and some question in what i did not understand

PLZ help

========================================================

the output should be as in the attachment file .

i wrote comments which starts with //

then i included   :     iostream    
                                  cmath
                                  iomanip

i used

 int main ()
{

return 0;
}

the expression of the formula is :

n-factorial = pow(exp,-n) * pow(n,n) * sqrt(2*n*PI) ;


and i declared   (    n-factorial   as  float  )

Are these right until now ??? before i complete .

hi somaja

i have the same problem and want somone 2 help me.

if u get any help plz let me know

thanks

hi somaja

i have the same problem and want somone 2 help me.

if u get any help plz let me know

thanks

lets solve it together :)

Can't you two just post the code you have right now and make stuff simpler?

post what u did squ ??\\

just 2 know

@somaja : Ya ya you have caught our attention , now can you please stop using the BOLD RED COLOURED text...??? And ya use code tags when posting your code.

@somaja & squ : Post in your progress in solving the program till now you will definitely get help from our side.

Problem :

Write a C++ program that asks the user to enter 5 large values of n ( > 10), calculates their factorial using sterling’s formula and displays the results in a tabular format.

Do what you can first :

>>Write a C++ program that asks the user to enter 5 large values of n ( > 10).

Can you do that ?

>>calculates their factorial using sterling’s formula and displays the results in a tabular format.

Can you make a function and try to do that ?

Take the sterling function apart, and see what you get.

FirstPerson :

int n1,n2,n3,n4,n5; //declaring values


cout<<"please enter five integer values"<<endl;
cin>>n1,n2,n3,n4,n5;
cout<<endl;

i will complete latter >>>> the second part

   //display on screen
   cout<<"Please enter five integer numbers > 10 :"<<endl;
   cin>>n1>>n2>>n3>>n4>>n5 ;
   cout<<endl;

//**************************************************************************************************  
   cout<<"Output format:"<<endl;
   cout<<"      "<<"scientific representation"<<endl;
   cout<<"      "<<"precision= default:"<<endl<<endl;
   cout<<fixed<<showpoint<<setprecision(5)<<endl;

   cout<<setw(10)<<"Num    "<<setw(10)<<"Sterling Value"<<endl;
   cout<<setw(10)<<"======="<<setw(10)<<"============="<<endl;

   cout<<setw(10)<<n1<< setw(10)<<n1-factorial<<endl;
   cout<<setw(10)<<n2<< setw(10)<<n2-factorial<<endl;
   cout<<setw(10)<<n3<< setw(10)<<n3-factorial<<endl;
   cout<<setw(10)<<n4<< setw(10)<<n4-factorial<<endl;
   cout<<setw(10)<<n5<< setw(10)<<n5-factorial<<endl;

//***********************************************************************************
   cout<<"Output format:"<<endl;
   cout<<"      "<<"non-scientific representation"<<endl;
   cout<<"      "<<"precision=2:"<<endl<<endl;
   cout<<fixed<<showpoint<<setprecision(2)<<endl;

   cout<<setw(10)<<"Num    "<<setw(10)<<"Sterling Value"<<endl;
   cout<<setw(10)<<"======="<<setw(10)<<"============="<<endl;

   cout<<setw(10)<<n1<< setw(10)<<n1-factorial<<endl;
   cout<<setw(10)<<n2<< setw(10)<<n2-factorial<<endl;
   cout<<setw(10)<<n3<< setw(10)<<n3-factorial<<endl;
   cout<<setw(10)<<n4<< setw(10)<<n4-factorial<<endl;
   cout<<setw(10)<<n5<< setw(10)<<n5-factorial<<endl;

return 0;

}

this is ma program .

can any one correct it and i missed sth i did not know what is it >>>???


PLZ

there is sth wrong on displaying the results
i mean numbers in scientific notation and the other one like in the attachement .

???

Have you by chance come across the phrase called "Compiling The Program" ??? I can definitely say that you haven't even compiled the program.
Because you have missed out on the very basic of which characters are allowed to form a variable.Since when did n1-factorial a variable and not variable n1 - variable factorial...???
And there are also many ambiguous calls in your function.

To solve these just compile your program on a good compiler.And debug the bugs.

hi again.

I do not understand how 2 apply the scientific representation??


can any one help plz??

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.