Advertisement
Guest User

Untitled

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