Help me in solving LOOOP6 problem

My issue

include <stdio.h>

int main() {
int i=1,n=7;
int fact = 1;
scanf(“%d”,&n);
for(i=1;i<=n;i++){
fact=fact*i;
}
printf(“%d”,fact);
}

My code

#include <stdio.h>

int main() {
    int i=1,n=7;
    int fact = 1;
    scanf("%d",&n);
    for(i=1;i<=n;i++){
        fact=fact*i;
    }
    printf("%d",fact);
}

Learning course: Learn C
Problem Link: Factorial of any number Practice Problem in C - CodeChef

#include <stdio.h>

// Function to calculate factorial
int factorial(int num) {
    int fact = 1; // Initialize the factorial variable to 1
    // Iterate from 1 to num and multiply each number to calculate factorial
    for (int i = 1; i <= num; i++) {
        fact *= i;
    }
    return fact; // Return the calculated factorial
}

int main() {
    int num; // Declare a variable to store user input
    printf(""); // Prompt the user to enter a number
    scanf("%d", &num); // Read the input number from the user
    
    // Calculate factorial by calling the factorial function
    int result = factorial(num);

    // Output the result
    printf("The factorial of the given number is: %d\n", result);
    
    return 0; // Indicate successful termination of the program
}

You should note two things:

  1. The factorial of 0 is 1. It should be included.
    2.The data type may fall short if the factorial is too large. You may use an array.

You may use this code. I made it work.

include <stdio.h>

int main() {
int num;
int fact = 1;
scanf(“%d”, &num);
for(int a = 1; a <= num; a = a + 1)
{
fact = fact*a;
}
printf(“The factorial of the given number is: %d \n”,fact);
return 0;
}

What problem you are getting?