Computer Science, asked by Deepak8851756552, 6 months ago

Write a c++ program to find factorial of a no. using for loop​

Answers

Answered by keyboardavro
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 anindyaadhikari13
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