programs look for combinations and permutations

Posted by Didi Setyapramana On 8:08 PM 0 komentar

# include <cstdlib>
# include <iostream>

using namespace std;

combinatorial class {
       public:
              void permutation ();
              combining void ();
       private:
              int i, n, r, p, t, a, b, c;
};

void combinatorial:: permutations () {
     cout <<"PERMUTATIONS" <<endl;
     cout <<"Enter n:";
     cin>> n;
     cout <<"Input r:";
     cin>> r;
     a = 1;
     b = 1;
     for (i = n; i> 0; i -)
     {
         a *= i;
     }
     t = n-r;
     if (t! = 0)
     {
         for (i = t; i> 0; i -)
         {
             b *= i;
         }
     }
     if (t! = 0)
     {
          p = a / b;
          cout <<"Result:" <<p <<endl;
     }
     else
     {
          cout <<a <<endl;
     }
}

void combinatorial:: combining () {
     cout <<"combining" <<endl;
     cout <<"Enter n:";
     cin>> n;
     cout <<"Input r:";
     cin>> r;
     a = 1;
     b = 1;
     c = 1;
     for (i = n; i> 0; i -)
     {
         a *= i;
     }
     t = n-r;
     if (t! = 0)
     {
         for (i = t; i> 0; i -)
         {
             b *= i;
         }
     }
     for (i = r i> 0; i -)
     {
         c *= i;
     }
  
  
     if (t! = 0)
     {
          p = a / (b * c);
          cout <<"Result:" <<p <<endl;
     }
     else
     {
          cout <<a <<endl;
     }
}
          
int main (int argc, char * argv [])
{
     combinatorial x;
     x.permutasi ();
     cout <<endl;
     x.combinasi ();
     cout <<endl;
  
     system ("PAUSE");
     return EXIT_SUCCESS;
}

Categories:

0 Response for the "programs look for combinations and permutations"

Post a Comment