PatrickSwayze

Untitled

Jan 10th, 2018
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.50 KB | None | 0 0
  1. /*
  2. 3. Napisz funkcję, która dla nieujemnej liczby n, takiej, że 0≤n≤20 wyznaczy dwusilnię.
  3. */
  4. #include <cstdlib>
  5. #include <iostream>
  6. using namespace std;
  7.  
  8. long long dwusilnia(int n)
  9. {
  10.   int wynik = 1;
  11.  
  12.   while (n>1)
  13.   {
  14.  
  15.       wynik*=n;
  16.       n=n-2;
  17.   }
  18.  
  19.   return wynik;
  20. }
  21.  
  22. int main()
  23. {
  24.   int n;
  25. poczatek:
  26.   cout<<"Podaj liczbe: ";
  27.   cin>>n;
  28.   if (n>0 && n<20)
  29.   {
  30.   cout<<"Dwusilnia z liczby "<<n<<" wynosi "<<dwusilnia(n)<<endl;
  31.   }
  32.   else goto poczatek;
  33.  
  34.   return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment