79. Write a program to perform factorial of given number?

#include<iostream.h>
#include<conio.h>
long factorial(int i);
void main()
{
                int n,result;
                clrscr();
                cout<<"Enter A Number For Factorial : ";
                cin>>n;
                result=factorial(n);
                cout<<"The Factorial of "<<n<<" = "<<result<<endl;
                getch();
}
long factorial(int i)
{
                if(i==0)
                                {
                                return 1;
                                }
                else
                                {
                                return(i*factorial(i-1));
                                }
}

79.PNG

Advertisements

Comments are closed.

Create a website or blog at WordPress.com

Up ↑

%d bloggers like this: