C Program to Find Factorial of a Number

This video tutorial explains how to write a c program to find the factorial of a number.
In this tutorial we are gonna ask the user to enter the number to find factorial. Then we calculate the factorial for the entered number and display it back to the user.



Source code for this video tutorial

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int number, counter, fact = 1;

    printf("Enter the number to calculate factorial\n");
    scanf("%d",&number);
    if( number < 0){
        printf("Enter non negative number");
    }else{
        for(counter = number; counter >= 1; counter--){

            fact = fact * counter;
        }
     printf("factorial of %d is %d",number,fact);
    }

    return 0;
}