Advertisement
Guest User

Untitled

a guest
Sep 18th, 2015
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.96 KB | None | 0 0
  1. #include<iostream>
  2. #include<conio.h>
  3. using namespace std;
  4. int fac(int a){
  5.     int b = 1;
  6.     for (int i = 1; i <= a; i++)
  7.         b *= i;
  8.     return b;
  9.  
  10. }
  11. int razA(int m, int n){
  12.     int r = (fac(n)) / fac((n - m));
  13.     return r;
  14. }
  15. int razB(int m, int n){
  16.     int r=n;
  17.     for (int i = 1; i <= m-1; i++){
  18.         r *= n;
  19.     }
  20.     return r;
  21. }
  22. int per(int n, int m) {
  23.     int n1;
  24.     int n2;
  25.     int down = 1;
  26.     for (int i = 1; i <= m; i++){
  27.         cout << "Vvedite N" << i << " element: ";
  28.         cin >> n1;
  29.         down *= fac(n1);
  30.     }
  31.     int r = fac(n) / down;
  32.         return r;
  33.    
  34. }
  35. int socA(int m, int n){
  36.     int r = (fac(n)) / (fac(m)*(fac(n - m)));
  37.     return r;
  38. }
  39. int socB(int m, int n){
  40.     int r = socA(m, n + m - 1);
  41.     return r;
  42. }
  43. int main(){
  44.     int result=0;
  45.     int m, n;
  46.     cout << endl<<"Choose type: \n1=r\n2=p\n3=s    ";
  47.     int choose1,choose2;
  48.     cin >> choose1;
  49.     switch (choose1){
  50.     case 1:
  51.         cout << endl<<"Choose s povtorami or not 1/2  ";
  52.         cin >> choose2;
  53.         switch (choose2){
  54.         case 1:
  55.             cout << endl<<"Type m and n cherez probel: ";
  56.             cin >> m >> n;
  57.             result = razA(m, n);
  58.         break;
  59.         case 2:
  60.             cout << endl<<"Type m and n cherez probel: ";
  61.             cin >> m >> n;
  62.             result = razB(m, n);
  63.         break;
  64.  
  65.         }
  66.         break;
  67.     case 2:
  68.         cout << endl<<"Choose s povtorami or not 1/2  ";
  69.         cin >> choose2;
  70.         switch (choose2){
  71.         case 1:
  72.             cout << endl<<"Type n: ";
  73.             cin >> n;
  74.             result = fac(n);
  75.         break;
  76.         case 2:
  77.             cout << endl<<"Vvedite n: ";
  78.             cin >> n;
  79.             cout << endl<<"Vvedite kol-vo Nn: ";
  80.             cin >> m;
  81.             result = per(n, m);
  82.         }
  83.     break;
  84.     case 3:
  85.         cout << endl<<"Choose s povtorami or not 1/2  ";
  86.         cin >> choose2;
  87.         switch (choose2){
  88.         case 1:
  89.             cout << endl<<"Type m and n cherez probel: ";
  90.             cin >> m >> n;
  91.             result = socA(m, n);
  92.             break;
  93.         case 2:
  94.             cout << endl<<"Type m and n cherez probel: ";
  95.             cin >> m >> n;
  96.         result = socB(m, n);
  97.             break;
  98.  
  99.         }
  100.     break;
  101.     }
  102.    
  103.     cout << "\nResult is: " << result;
  104.     cout << "\nPress anykey for exit";
  105.     char ak;
  106.     ak = _getch();
  107.     return 0;
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement