Today we'll write a very fine and efficient program using c language to get the factorial of the given number.
For this we'll use Code Blocks Compiler. Click the below link to get its setup file. Then install it.
Download CodeBlocks Setup
So, let's get started for coding. Start Codeblocks and Click on "Create a New Project" and then click on Files from the left Panel and select C/C++ Source File, then click OK. Now just copy and paste he below code:
#include <stdio.h>
int main()
{
int num, i=1, factorial=1;
printf ("Enter a number: ");
scanf ("%d", &num);
for (i=1;i<=num;i++)
{
factorial = factorial*i;
}
printf ("\nThe factorial of %d is %d.",num,factorial);
return 0;
}
For this we'll use Code Blocks Compiler. Click the below link to get its setup file. Then install it.
Download CodeBlocks Setup
So, let's get started for coding. Start Codeblocks and Click on "Create a New Project" and then click on Files from the left Panel and select C/C++ Source File, then click OK. Now just copy and paste he below code:
#include <stdio.h>
int main()
{
int num, i=1, factorial=1;
printf ("Enter a number: ");
scanf ("%d", &num);
for (i=1;i<=num;i++)
{
factorial = factorial*i;
}
printf ("\nThe factorial of %d is %d.",num,factorial);
return 0;
}
Now click on Build and then click on Compile Current File.
Then again click on Build and click on Run.
Now the program will run. It will work fine. Run it enter any number such as 5 and then Enter.
It will show you 120 which is the factorial of 5.
Happy Coding!!!
Then again click on Build and click on Run.
Now the program will run. It will work fine. Run it enter any number such as 5 and then Enter.
It will show you 120 which is the factorial of 5.
Happy Coding!!!