Hi everyone!
I am new to the board and new to Unix. Getting used to it but still have alot of trouble with it.
I need to write a program that generates factorial of a number by input of the user. It should be an input between 1 and 10 and check to see if it is within a range. I should also write a function called "factorial" which has a prototype of void factorial(int num); and finally, I should call the function to from the main program. here is what i got so far. any input, tips, or anything at all would be greatly appreciated. i really need the help. i look forward and greatly appreciate any help and hope to learn alot more with you all at this site.
Code:
# include <stdio.h>
# include <math.h>
void factorial(int num);
int main(void)
{
int num;
int factorial;
int factor;
printf("Enter a positive integer between 0 and 10: ");
scanf("%d", &num);
if (num < 0){
printf("This negative factorial %d will be undefined.\n", num);
}else if (num <=10){
factor = factorial(num);
printf("The factorial of %d is %d\n", num, factor);
}else {
printf("Number is out of the range of. Please try again\n");
}
return (0);
}
void
void
factorial(int num)
{
int num_a = num;
int factor_1 = 1;
int factor;
factor = factor_1 * num_a;
return(factor);
}