Factorial in c++

Factorial in c++
  20 April 2021
Read more Like this Post.
simple code of factorial programme
using namespace std;

int main(){
  int f, r = 1;
  cout << "Enter positive number to find factorial: ";
  cin >> f;
  if(f >= 0){
    for(int i = 1; i < f; ++i){
      r = f * i;
    cout << "Factorial is: " << r;
    cout << "Enter only positive numbers! \n";
    return 0;
this is the simple programme in c++ which can find factorial. #practical there is 2 variables f and r. f for factorial number and r for resulting integer. r is initialized by 1. cin for input also from user. which accept only positive integers and this value is stored in f than a condition which check if f is greater than 0 or not. after checking if f is greater than 0 a for loop will run at (int f)times and multiplied by (i) which we declared for incrementing value of for loop in last we show the result ( cout << r ;).
Related Post's

cpp   loops   function   classes   factorial  
Not Loaded Zohaib Jozvi
0 20 April 2021
Read Latest Post.
Read other post.