Advertisement
Guest User

Untitled

a guest
Nov 18th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.76 KB | None | 0 0
  1. #include <iostream>
  2. #include <ctime>
  3.  
  4. using namespace std;
  5.  
  6. long factorial(long number){
  7.    
  8.     long result = 1;
  9.    
  10.     for (int i = 1; i <= number; ++i){
  11.         result = result * i;
  12.     }
  13.    
  14.     return result;
  15. }
  16.  
  17. long NewtonBinom(int n, int k){
  18.     long result = factorial(n) / (factorial(k) * factorial(n-k));
  19.     return result;
  20. }
  21.  
  22. int main()
  23. {
  24.     int n, k;
  25.     cout << "Wpisz liczbe n: "  << endl;
  26.     cin >> n;
  27.     cout << "Wpisz liczbe k: " << endl;
  28.     cin >> k;
  29.    
  30.     if (n < k){
  31.         cout << "Niepoprawne liczby. Liczba n musi być większą równą k";
  32.     }
  33.     else{
  34.         int binom = NewtonBinom(n, k);
  35.         cout << "Symbol newtona dla liczb n = " << n << " oraz k = " << k
  36.         << " równa się " << binom;
  37.     }
  38.        
  39.    
  40.    
  41.     return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement