Code goes like this :
/* Factorial calculation using While loop */
#include<stdio.h>
#include<conio.h>
int main()
{
int i,num,fact=1;
i=1; //counter initialization
printf("Enter any number: ");
scanf("%d",&num);
while(i<=num)
{
fact*=i; //Factorial calculation
i++; //Counter Increment
}
printf("\n The factorial of %d is %d",num,fact);
return 0;
}
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
Home / C Programming /
Factorial Calculation /
Looping in C /
While Loop
/ Factorial using while loop in C Programming
- Blogger Comment
- Facebook Comment
Subscribe to:
Post Comments
(
Atom
)
0 comments:
Post a Comment