0
Can someone tell me why it using int factorial.. And not using void factorial?
3 Answers
+ 2
Because a factorial returns an interger in that function whereas void factorial() does return anything . eg int factorial(int number){
int o=1;
for (number=number; number<=1; ++number){
o=numberĂo;
}
return o;
int main (){
int your_number;
scanf("%d",&your_number);
printf("Factorial of %d is %d\n",your_number,factorial(your_number));
return 0;
}
i can use factorial(int ....) because i know it has returned(given out ) only the factorial integer. Okay? /*This code is c try to change to c++ to enhance your progranming skills).
+ 1
Thank you very much
0
Because in the factorial function you are multiplying a defined number of integers and returning them as the result, i.e. giving an int output, you have to define the function as int factorial. If the function does not return a value, i.e. just do something in the function body without returning something, you have to define the function as void factorial.