Monday, 15 August 2011

c - For loop is running only once -



c - For loop is running only once -

int input; int factorial; int half; printf("enter number wish calculate: "); scanf("%d", &input); for(x=1; x<input; x++); { half = input - 1; factorial = input * half; } printf("%d\n", factorial); homecoming 0;

it's running once, giving me input number * (input number - 1), exam, input 5 giving out 20. doing wrong preventing continuing running?

you have ; after for-loop. remove , you'll fine:

for(x=1; x<input; x++) { // stuff }

you still have prepare error in loop, mentioned in other answers.

c

No comments:

Post a Comment