Pages

Tuesday, June 17, 2025

Factorial of N in C++

 


#include <iostream>

using namespace std;



// Factorial of N


int factorial(int n) {

    if (n == 0) {

        return 1;

    }

    

    return n * factorial(n-1);

}


int main() {

   

    cout << factorial(5);


    return 0;

}

No comments:

Post a Comment

3Sum - Leetcode solution - How i turned into two-pointer approach?

  class Solution {     public List < List < Integer >> threeSum ( int [] nums ) {         Arrays . sort (nums); // first sort...