WAP to find the factorial of a number using while loop

Write a program to find the factorial of a number using while loop

#include<stdio.h>

void main() {
	int n,fact=1;
	printf("Enter any number: ");
	scanf("%d",&n);
	while(1) {
		if(n==0) break;
		fact*=n;
		n--;
	}
	printf("Factorial = %d",fact);
}

Output

Enter any number: 5
Factorial = 120

0 0 votes
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments