Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Program to display factorial of a number.
- #include<iostream.h>
- #include<conio.h>
- fac(int);
- void main()
- {
- clrscr();
- int a;
- char z;
- do
- {
- cout<<"Enter a number: ";
- cin>>a;
- a=fac(a);
- cout<<"The factorial is: "<<a<<endl;
- cout<<"Do you wish to display another factorial? (y/n): ";
- cin>>z;
- }
- while(z=='y'||z=='Y');
- }
- fac(int a)
- {
- int i,b;
- for(i=1,b=1;i<=a;i++)
- b=b*i;
- return b;
- }
Advertisement
Add Comment
Please, Sign In to add comment