Question

Write a program in C that uses recursion to calculate and print the factorial of the...

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".

Homework Answers

Answer #1

*
* 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));
}
}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Write a program on C++ to calculate and print the factorial of a number using a...
Write a program on C++ to calculate and print the factorial of a number using a for loop. The factorial of a number is the product of all integers up to and including that number, so the factorial of 4 is 4*3*2*1= 24.
in c++ Write a C++ program that asks the user to enter an integer number and...
in c++ Write a C++ program that asks the user to enter an integer number and prints it back "vertically" to the screen. Use recursion in your solution. As an example of how the program will work: Please enter an integer: 12345 The integer you entered will print vertically as: 1 2 3 4 5
In C++ Using recursion write a program that takes a positive integer number and returns whether...
In C++ Using recursion write a program that takes a positive integer number and returns whether there is 6. For example, if the input number is 7068, the function returns true
Write a C++ program with a user-defined function myFactorial, that calculates the factorial of a number...
Write a C++ program with a user-defined function myFactorial, that calculates the factorial of a number entered by the user. Return the calculated factorial and print it in the main function.
How to code this in python Write a program that computes and prints the first 1000...
How to code this in python Write a program that computes and prints the first 1000 prime numbers - simply write out each prime number on a new line. In implementing this solution I want you to define 2 functions: is_prime which can be used to test whether a number is a prime (e.g. is_prime(17) returns True but is_prime(9) returns False) and compute_primes which will return an array (or Python list) of the first n primes where n is passed...
IN JAVA 1. Write up a small program that accepts two integers from the user. Print...
IN JAVA 1. Write up a small program that accepts two integers from the user. Print which of the two values is bigger. If they are the same, print that they are the same. 2. Write a method that accepts three doubles. Calculate and return the average of the three passed double values. 3. Write up a method that accepts a score between 0-10. Print out a message according to the following table. You ay personally decide the boundaries. i.e.,...
(in java) a. Include a good comment when you write the method described below: Write a...
(in java) a. Include a good comment when you write the method described below: Write a method factorial which receives a positive integer n and calculates n! (n factorial), defined as follows: n!=1*2*…*(n-1)*n. For example, 5! = 1*2*3*4*5 = 120. The method should return this value to the calling program. b. Write a driver program (main method) which will read an integer from the console, and pass it to the method to calculate its factorial. The main method then prints...
Write a MATLAB program to determine the factorial value of an input integer between 1 and...
Write a MATLAB program to determine the factorial value of an input integer between 1 and 30. You may NOT use the built-in factorial function. You must implement it using a for loop. Display the result back to the user with 2 decimal places (yes, 2 decimal places). The result should follow the following format:   The factorial value is *.xx
using C++ 1) write a program to calculate to avg of N number of subjects. 2)write...
using C++ 1) write a program to calculate to avg of N number of subjects. 2)write a program to find the factorial of 5! 5*4*3*2*1 3)write a program to display the multiplication table for any number please enter number : 3 1*3=3 2*3=6 2*4= 10*3=30 4) find the factorial on n
1- Write a program to print only the even numbers from 100 to 200 2- Write...
1- Write a program to print only the even numbers from 100 to 200 2- Write a program to print the odd numbers from 22 – 99 3- Write a program to calculate howe many even number from 10 to 120 1- Write a program to find only the even numbers for 12 different numbers 2- Write a program to find the odd numbers for 10 different numbers 3- Write a program to calculate howe many even number and how...