Pages

Friday 18 March 2011

PROGRAM TO FIND THE FACTORIAL USING THE FUNCTION

DESCRIPTION-:This program calculate the factorial of the given number using the function.In function call we pass the one parameter and in function definition we use for loop to calculate the factorial of the given number.
FOR EXAMPLE-:If we enter number as--------
                                                            5
Then it generate output as---------------
                                     Factorial of number is =120


PROGRAM-:
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int fact(int);
int n,i,k;
cout<<"enter any number";
cin>>n;
k=fact(n);
cout<<"factorial of number is=  "<<k;
getch();
}
int fact(int x)
{
int fact=1;
if(x==0||x==1)
{
cout<<"factorial of number is"<<fact;
}
else
{
for(int i=2;i<=x;i++)
{
fact=fact*i;
}
}
return(fact);
}

0 comments:

Post a Comment

 
Copyright (c) 2010 Concepts Of C++. Design by WPThemes Expert

Blogger Templates and RegistryBooster.