ajprincess
  • ajprincess
Plzz help. write a C++ program to find the factorial of a number using keyboard input.
Computer Science
  • Stacey Warren - Expert brainly.com
Hey! We 've verified this expert answer for you, click below to unlock the details :)
SOLVED
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
katieb
  • katieb
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
ajprincess
  • ajprincess
Suppose if the entered number is 5 then your output should be as follows. 5*4*3*2*1=120. How do u do this.
anonymous
  • anonymous
int n; // this is user input long fact = 1; for (int i = n; i>0; --i) { fact *= i; } cout<=0) before for loop.
ajprincess
  • ajprincess
output will b only 120 right?

Looking for something else?

Not the answer you are looking for? Search for more explanations.

More answers

ajprincess
  • ajprincess
My coding is this #include using namespace std; void disfactorial(); int main() { disfactorial(); system("PAUSE"); return 0; } void disfactorial() { int num, fact=1; cout<<"Enter the number:"; cin>>num; for(int i=num;i>1;i--) { fact=fact*i; } cout<
ajprincess
  • ajprincess
When I enter 5 I get the output as 120. I want it to display 5*4*3*2*1=120. Hw can I edit my code to display this?
eSpeX
  • eSpeX
A suggestion would be to implement your user interaction within the main: int main() { int fact; cout<<"Enter the number:"; cin>>num; fact = disfactorial(num); cout<<"The factorial of " + 5 + " is " + fact<
eSpeX
  • eSpeX
To fix your code to produce 120 as the output you would just need to change your loop: from this: for(int i=num;i>1;i--) { fact=fact*i; } to this: for(int i=1;i
ajprincess
  • ajprincess
I dnt get the correct output.
eSpeX
  • eSpeX
I had some compilation errors, mixed java and c++ syntax. Try this: #include using namespace std; int disfactorial(int x); int main() { int fact, num; cout<<"Enter the number:"; cin>>num; fact = disfactorial(num); cout<<"The factorial of " << 5 << " is " << fact<
eSpeX
  • eSpeX
input: 5 output: Enter the number:The factorial of 5 is 120
ajprincess
  • ajprincess
I got the same output for my coding above.
ajprincess
  • ajprincess
I changed ur code and only compiled bt didnt get the output.
eSpeX
  • eSpeX
If you are getting 120 as the factorial of 5, which it is, then I must have misunderstood the question, I apologize. What were you having difficulty with?
ajprincess
  • ajprincess
I want the output like this 5*4*3*2*1=120 Nt jst 120
eSpeX
  • eSpeX
OH! You are looking at formatting..
eSpeX
  • eSpeX
With the smaller numbers it will be simple to just hard code them, but you could always create an array the size of your "num" and set each index as you step through your for loop. However you should consider that if this code were to be used on a large number, say 50, you would have text scrolling across the screen.
ajprincess
  • ajprincess
it's true. Thanxxxxxxxxxxxx a lot
anonymous
  • anonymous
the factorial grows really fast, so you get integer overflow once you go after about 20! or something
anonymous
  • anonymous
I wonder if C++ has bignums included in the library.
eSpeX
  • eSpeX
I'm fairly certain they have long unsigned double, that's fairly big. :)

Looking for something else?

Not the answer you are looking for? Search for more explanations.