Pages

Friday, March 28, 2025

Find factorial of a number entered by the user in C++

 #include <iostream>

#include <cmath>
using namespace std;
/*
pseudocode:
1. user enters the value
2. the factorial-> 5! - 1 x 2 x 3 x 4 x 5
so, it is the addition of that number + multiplied after, until value entered reached.
*/

// Find factorial of a number entered by the user.
int main(){
    int n = 6;
    int fact = 1;

    for(int i = 1; i <= n; i++){
        fact *= i;
    }

    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...