C program to find the factorial of a number.

Here is a program to find the factorial of a number.

#include<stdio.h>

int fac(int n);

int main() {
    printf("Here is a program to find the factorial of a number using functions\n");
    printf("Enter a num to find the factorial:");
    int n = 0;
    scanf("%d", &n);
    int ans = fac(n);
    printf("The factorial is: %d\n", ans);  // is added \n for a new line
    return 0;
}

int fac(int n) {
    int fact = 1;
    for (int i = 1; i <= n; i++) {
        fact = fact * i;
    }
    return fact;
}

This is the main part of the code.

int fac(int n) {
    int fact = 1;
    for (int i = 1; i <= n; i++) {
        fact = fact * i;
    }

Hope you learnt something because of this blog. Dont forget to follow.

Thankyou...