Sunday, 6 September 2020

Program to find the factorial of a number

/*A program to find the factorial of a given number*/
#include<stdio.h>

int main()
{
int i,a,fact;
fact=1;
printf("Enter the number");
scanf("%d",&a);
for(i=1;i<=a;i++)
{
fact=fact*i;
}
{printf(" %d!=%d",a,fact);
}
return 0;
}

OUTPUT:

Meaning of factorial:
2!=2*1=2
4!=4*3*2*1=24
5!=5*4*3*2*1=120
DESCRIPTION:
Here in this program we ask the user to input a number and by the use of the for loop, we calculate the factorial of the number.


2 comments:

  1. Sir, I was really confuse on finding factorial of a number. I tried several times but I couldn't do. But after watching this post you made me clear. This program is simple and very clear. You are the hero sir. Please keep posting more programs daily. I love you sir😍😍
    .
    .
    .
    .
    .
    .
    .
    .
    .
    Kaisa laga mera mazak😂😂

    ReplyDelete
    Replies
    1. Hey Dilip B.K. thanks for your feedback on it.

      Delete

If you have any doubt, please ask in the comment section.

Search This Blog

Program to print weather the number is happy or not.

#include <stdio.h> #include <math.h> int main () { int i , j , num , temp , sum = 0 ; printf ( "Enter number\n...