Final answer:
To calculate the factorial correctly, there are a few errors in the provided code. The corrected code is included.
Step-by-step explanation:
To calculate the factorial correctly, there are a few errors in the provided code that need to be fixed:
- The line 'Printf("Enter the number:");' is missing a semicolon at the end.
- The line 'Scanf("%",&num);' should have '%d' instead of '%'. Additionally, there should be an ampersand (&) before 'num' to properly read the input value.
- The 'For' loop condition should be 'i<=num' instead of 'i,num'.
- The line 'J=j*i;' should be 'j=j*i;' to properly assign the calculated value to 'j'.
Here is the corrected code:
#include <stdio.h>
int main() {
int i, num, j;
printf("Enter the number: ");
scanf("%d",&num);
j=1;
for (i=1; i<=num; i++) {
j=j*i;
}
printf("The factorial of %d is %d
",num,j);
return 0;
}