Here is an recursive program, to calculate the factorial of a given number.
#include
#include
unsigned long factorial(int n);
void main()
{
clrscr();
int n;
printf("Enter the number for the factorial ");
scanf("%d",&n);
if(n <= 0)
{
printf("no factorial for -ve numbers");
getch();
return;
}
unsigned long fact = factorial(n);
if((long)fact > 0)
printf("The factorial of %d is %ld\n",n,fact);
else printf("Number too big");
getch();
}
unsigned long factorial(int n)
{
if (n == 1) return 1;
long old_fact = factorial(n-1);
if ((long)old_fact < 0)
{
return -1;
}
else
return (n * old_fact);
}
2006-11-26 22:02:10
·
answer #1
·
answered by manoj Ransing 3
·
0⤊
0⤋
C++ Syntax (Toggle undeniable textual content) int major() { int num; do{ cout << "enter a quantity between a million and 10"; cin>>num; }at the same time as( num < a million || num > 10 ); /* ask some extra if we dont get something between a million and 10 */ double factorial( num ); for( int n(num-a million) ; n > 0 ; factorial *= n, --n); /* demonstration of ways the for loop must be particularly functional */ cout << "The factorial of "<< num << " is "<< factorial << endl; }
2016-11-27 00:57:14
·
answer #2
·
answered by apps 3
·
0⤊
0⤋
Check out the http://openoffice.org suite it has a program for flowcharts I believe if not then sorry.
2006-11-26 18:50:42
·
answer #3
·
answered by jack 6
·
0⤊
0⤋
Refer Let us C by yashwanth kanethkar
u will get it
2006-11-26 21:40:40
·
answer #4
·
answered by smartsuman2k1 2
·
0⤊
0⤋