solved factorial using the while loop in C++ language

pull/1229/head
Kiran1810 2023-08-04 23:04:53 +05:30
parent d3c2184af8
commit 70e9379981
1 changed files with 14 additions and 1 deletions

View File

@ -30,7 +30,7 @@ int main() {
cin>>n;
cout<<"factorial is: "<<factorial(n);
return 0;
}
/*
Input:
@ -40,3 +40,16 @@ Enter a number:
Output:
factorial is: 6
*/
// factorial is solved using the while loop
int m;
cout << "Enter a number: ";
cin>>m;
int factorial = 1;
int j = 1;
while (j <= m) {
factorial = factorial * j;
j++;
}
cout << "factorial of the given number is :" <<factorial;}