bsc

Comprehensive codebase and coursework for the 4-year B.Sc. Computer Science Honours degree (WBSU)

git clone https://github.com/notamitgamer/bsc.git
· rebuilt hourlyOpen on GitHub
root / semester_2 / practice / prac_012.cpp

prac_012.cpp (472B)


      1 /* factorial using loop */
      2 
      3 #include <iostream>
      4 using namespace std;
      5 
      6 class fact {
      7     int inp, a = 1, i;
      8 
      9 public:
     10     void input();
     11     void calc();
     12     void output();
     13 };
     14 
     15 void fact::input() {
     16     cout << "enter the number :";
     17     cin >> inp;
     18 }
     19 
     20 void fact::calc() {
     21     for (i = 1; i <= inp; i++) {
     22         a = a * i;
     23     }
     24 }
     25 
     26 void fact::output() {
     27     cout << "factorial : " << a;
     28 }
     29 
     30 int main() {
     31     fact z;
     32     z.input();
     33     z.calc();
     34     z.output();
     35     return 0;
     36 }