Help!


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Help!
# 1  
Old 11-08-2006
Bug Help!

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

}

cheers

Last edited by reborg; 11-08-2006 at 09:23 PM..
# 2  
Old 11-08-2006
If you take a look at our rules you'll see that homework and assignment questions are not permitted.

Thanks
ZB
 
Login or Register to Ask a Question

Previous Thread | Next Thread
Login or Register to Ask a Question