Pages

Thursday, April 10, 2025

Finding Factorial in C++

 #include <iostream>

using namespace std;


int main() {

    int n, i, f = 1;

    

    cout << "enter a num : ";

    cin >> n;

    

    

    if( n == 0 ) {  // n should be assigned to 0

        cout << "Factorial; " << f << endl;

    } else {

    

    for(i = 1; i <= n; i++) {

        f = f*i;


        }

        

        cout << "Factorial: " << f << endl; // result come outside the for loop, inside for loop you only see the process BTS

    }

    return 0;

}


No comments:

Post a Comment

Encode and Decode Strings - NeetCode.IO Solution by me + gemini pro 3.0 explained

  class Solution {         // encode: List of Strings -> String     public String encode ( List < String > strs) {         Stri...