Factorial calculation of a given number using C Programming

 Program for Factorial Calculation in C using For Loop

 Algorithm Development : 

Step 1 : Start
Step 2 : initialize fact=1, i=1
Step 3 :  Read the number
Step 4 : Repeat step 4 through 6 until i=n
Step 5 : fact=fact*i
Step 6 : i=i+1
Step 7 : Print fact
Step 8 : Stop


 Flowcharting : 






Code goes like this :

/* Program for calculating factorial */
#include<stdio.h>
main()
{
    int i, num,fact=1;
    printf("Enter any number :");
    scanf("%d",&num);
    for(i=1;i<=num;i++)
    {
    fact=fact*i;
    }   
    printf("\n The factorial of %d is: %d",num,fact);
}

Output :











I have used Dev CPP to compile this program. If you are using Turbo C++ IDE, then use conio.h in link section after stdio.h and use getch(); to hold the output screen, just before the end of main function.
If you have any confusion regarding the program, please, comment below.
Happy Coding !
Thank you.
Share on Google Plus

About Nepali Xoro

Interested in Information Technology, Spreading Knowledge for Nepalease IT Students."Loves Traveling", Listen Music and Surfing web.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment