All articles
c

A program to find the FACTORIAL value of a given number (DO WHILE)

Share this article

Share on LinkedIn Share on X (formerly Twitter)

C Programming Language 032

The following code shows how to write a program to find the FACTORIAL value of a given number (DO WHILE).

Program

#include <stdio.h>
 
void main()
{
    int i, fact = 1, n;
 
    printf("Enter a number: ");
    scanf("%d", &n);
 
    i = 1;
    do
    {
        fact = fact * i;
        i++;
    } while (i <= n);
    printf("%d factorial = %d", n, fact);
 
    printf("\n");
}

Result

Enter a number: 4
4 factorial = 24

Comments