Hi,
I am a newbie, and i am trying to write my first few simple programs in C. In the following example i am trying to write a small program which gives me the factorial of a particular number, however, when i hit the "x" key, i would like to terminate the program.
This is the code which i tried:
When i run the program, it works fine, however, as soon as i hit the "x" key the program will run into an endless loop giving me the factorial number of the last number which i checked for.Code:/*Program to find the factorial of 6 */ #include <stdio.h> int i,j; int value; int main() { char keypress; do { printf("Enter a value to which you want the factorial: "); scanf("%d", &value); j=1; for (i=1; i<=value; i++) j=j*i; printf("The factorial of %d is %d\n", value, j); } while (keypress != "x"); return 0; system("PAUSE"); }
Can someone tell me what i do have wrong please ?
Many thanks in advance.