Hey guys. Need some Loop Help.

Hey Guys. I needed a loop that asks the user if he/she would like to compute. [turbo C]
Thank you and Happy new year~ :)


Here is my code:




#include <stdio.h>
#include <stdlib.h>
int num, fact = 1;
main()
{

printf("Input a non-negative integer: \n ");
scanf("%d", &num);

for(int i=1; i<=num; i++){
fact = fact * i;
}

printf("The factorial of %d is %d", num, fact);

system ("pause");
}


Please use turbo C. :)
Last edited on
In that case, you should create your own factorial function. If you remember the definition of a factorial, it should't be that difficult. Also, it's common to use integers for iterating a for loop. And finally, creating a factorial like that will not support decimals, and therefore, there is no reason to use a float. Your entire code can be rewritten to use integers!

EDIT: By the way... is that main function definition allowed C syntax? I am not very experienced with C, but I highly doubt that is acceptable code.
Last edited on
before creating any program you have to check it on daily routine and its all steps .. then change same thing in coding .. that will be easy for you .. specily for loops...
Topic archived. No new replies allowed.