print the factorial of user input



Factorial number  

In mathematics, the factorial of a positive integer n, denoted by n!, is the product of all positive integers less than or equal to n: n!=n×(n-1)×(n-2)×(n-3)×⋯×3×2×1. For example, 5!=5×4×3×2×1=120, where The value of 0! is 1.  


QUESTION:- print the factorial of user input  

#include <stdio.h>

#include <conio.h>

int main()

{

    int nofact = 1;

    printf("enter a value of a: ");

    scanf("%d", &no);

    for (int i = 1i <= noi++)

    {

        fact = fact * i;

        printf("%d! = %d  \n"nofact);
    }

    printf("the factorial of %d is %d "nofact);

    getch();
}


OUTPUT

enter a value of a: 4

4! = 1  

4! = 2

4! = 6

4! = 24

the factorial of 4 is 24

Follow our page for regular updates.

0 Comments