Compute the Factorial of a Number - C Data Type

C examples for Data Type:int

Introduction

The factorial of a positive integer n is denoted by n! and is defined as follows:

n! = 1 x  2 x  ..... x  n

For example,

0! = 1                          (by definition)
1! = 1
2! = 1 x 2 = 2
3! = 1 x 2 x 3 = 6

Demo Code

#include <stdio.h>

int main(){//from   www . j  a  v  a 2  s .  c o m
     int counter=  10;
     unsigned long int result = 1;
     char ch;
    
     for (int i = 1; i <= counter; i++) {
        result = result * i;
     }
        
     printf("Required factorial is: %lu\n", result);

     return(0);
}

Result


Related Tutorials