0

Can someone tell me why it using int factorial.. And not using void factorial?

13th Oct 2016, 4:29 AM
Seinsora x
Seinsora x - avatar
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).
13th Oct 2016, 5:01 AM
THE.GEEK
THE.GEEK - avatar
+ 1
Thank you very much
15th Oct 2016, 5:44 PM
Seinsora x
Seinsora x - avatar
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.
29th Oct 2016, 11:17 AM
Varya