I need to get the factorial of the number n inputted by the user and I have to use the for loop without a body to get the factorial. But in that case the scope of the variable k is the for loop, and when I try to print the k after the loop, it prints 1 (i. e. the value as k was initialized). What can I do?
Code:#include <stdio.h> int main(void) { int n, k = 1; scanf("%d", &n); for (int i = 1, k; i <= n; k *= i, i++); printf("%d", k); return 0; }