Q2 Write a c program to find the factorial value of any number entered through the keyboard.

Write a program to find the factorial value of any number entered through the keyboard.

Program: 95

Write a c program to find the factorial value of any number entered through the keyboard.

#include<stdio.h>
#include<conio.h>
int main()
{
    int num, fact=1, n;
    printf("Enter a number: ");
    scanf("%d", &num);
    n = num;
    while (num!=0)
    {
        fact = fact*num;
        num = num-1;
    }

    printf("The Factorial for %d is %d", n, fact);
}

Output:

 Enter a number: 5
 The Factorial for 5 is 120

Lokesh Kumar: Being EASTER SCIENCE's founder, Lokesh Kumar wants to share his knowledge and ideas. His motive is "We assist you to choose the best", He believes in different thinking.

View Comments (3)

    • Some old compilers doesn't support console input/Output without conio.h header files. It's not a part of standard library.
      It's my habit, you can ignore it because modern compiler doesn't need conio.h.
      and Thanks for choosing EasterScience

      did you checked our COVID-19 Tracker

  • //it can be done in this way also?
    #include<stdio.h>
    main()
    {
    int num,i,n=1;
    printf("enter a number");
    scanf("%d",&num);
    for(i=1;i<=num;i++)
    {
    n=n*i;
    }
    printf("fectorial is %d",n);
    }

Related Post
Leave a Comment

This website uses cookies.