Write a program in C that uses recursion to calculate and pr

Write a program in C that uses recursion to calculate and print the factorial of the positive integer value passed in or prints the line \"Huh?\" if no argument is passed or if the first argument passed is not a positive integer. If the value passed in exceeds 10, you can simply print \"Overvalue\".

Solution

*
* C Program to find factorial of a given postive number using recursion
*/
#include <stdio.h>

int fact(int);

int main()
{
int n;
int result;

printf(\"Enter a number to find it\'s Factorial: \");
scanf(\"%d\", &n);
if (n < 0 || n == \"\")
{
printf(\"Huh?\ \");
}
else if( n > 10)
{

printf(\"Overvalue\ \");
}
else
{
result = fact(n);
printf(\"The Factorial of %d is %d.\ \", n, result);
}
return 0;
}
int fact(int num)
{
if (num == 0 || num == 1)
{
return 1;
}
else
{
return(num * fact(num - 1));
}
}

Write a program in C that uses recursion to calculate and print the factorial of the positive integer value passed in or prints the line \

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site