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".
*
* 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?\n");
}
else if( n > 10)
{
printf("Overvalue\n");
}
else
{
result = fact(n);
printf("The Factorial of %d is %d.\n", n, result);
}
return 0;
}
int fact(int num)
{
if (num == 0 || num == 1)
{
return 1;
}
else
{
return(num * fact(num - 1));
}
}
Get Answers For Free
Most questions answered within 1 hours.