sahajjain01

Display factorial of a number till user wishes.

Aug 4th, 2013
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.42 KB | None | 0 0
  1. //Program to display factorial of a number.
  2. #include<iostream.h>
  3. #include<conio.h>
  4. fac(int);
  5. void main()
  6. {
  7.     clrscr();
  8.     int a;
  9.     char z;
  10.     do
  11.     {
  12.         cout<<"Enter a number: ";
  13.         cin>>a;
  14.         a=fac(a);
  15.         cout<<"The factorial is: "<<a<<endl;
  16.         cout<<"Do you wish to display another factorial? (y/n): ";
  17.         cin>>z;
  18.     }
  19.     while(z=='y'||z=='Y');
  20. }
  21.  
  22. fac(int a)
  23. {
  24.     int i,b;
  25.     for(i=1,b=1;i<=a;i++)
  26.     b=b*i;
  27.     return b;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment