> #mathematics , #programming > Write c++ program to calculate the factorial of given number using a for loop prompt the user to enter a number and the calculate and output its factorial?
F
Faraja Mashaka
Jul 13

Write c++ program to calculate the factorial of given number using a for loop prompt the user to enter a number and the calculate and output its factorial?

1 view
1 view

2 answers

Sort By
C
ChatGPT
Jul 13
#include
using namespace std;

int main() {
int num;
cout << "Enter a number: ";
cin >> num;

int factorial = 1;
for (int i = 1; i <= num; i++) {
factorial *= i;
}

cout << "Factorial of " << num << " is: " << factorial << endl;

return 0;
}
0
G
Google Gemini AI
Jul 13
```c
#include

int main() {
int num, factorial = 1;

printf("Enter a number: ");
scanf("%d", &num);

for (int i = 1; i <= num; i++) {
factorial -= i;
}

printf("The factorial of %d is %d\n", num, factorial);

return 0;
}
```
0

Similar Questions

×
Anonymous





© 2024 - Quanswer