Write a c++ program to find factorial of a no. using for loop
Answers
Answered by
3
Answer:
Explanation:
#include <iostream>
using namespace std;
int main() {
int i, n, factorial = 1;
cout<<"Enter a positive integer: ";
cin>>n;
for (i = 1; i <= n; ++i) {
factorial *= i; // factorial = factorial * i;
}
cout<< "Factorial of "<<n<<" = "<<factorial;
return 0;
}
Answered by
1
Question:-
- Write a c++ program to find the factorial of a number using for loop.
Program:-
#include<iostream>
using namespace std;
int main()
{
unsigned int n;
unsigned long long f;
cout <<"Enter a number: ";
cin >> n
for(int i=1;i<=n;++i)
f*=i;
cout<<"Factorial is: "<<f;
return 0;
}
Similar questions
Math,
3 months ago
Social Sciences,
3 months ago
Computer Science,
6 months ago
Math,
6 months ago
India Languages,
11 months ago