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

Stack using Linked List – Partial (University Exam Topic)

 #include <iostream> using namespace std; struct Node {     int data;     Node* next; }; class Stack {     Node* top; public:     Stac...