vertc

14-02

Feb 14th, 2017
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.30 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. long long silnia(int n) {
  6.     if (n<1)
  7.     return 1;
  8.     return n*silnia(n-1);
  9. }
  10.  
  11. int main () {
  12.     int n;
  13.     cout<<"Podaj liczbe: ";
  14.     cin>>n;
  15.     cout<<"Silnia z "<<n<<" wynosi: "<<silnia(n)<<endl;
  16.     return 0;
  17. }
  18.  
  19. -------------------------------------------------------------------------------------
  20.  
  21. #include <iostream>
  22.  
  23. using namespace std;
  24.  
  25. long long wartosc(int n) {
  26.     if (n==1)
  27.     return -3;
  28.     return wartosc(n-1)*4+(2*n);
  29. }
  30.  
  31. int main () {
  32.     int n;
  33.     cout<<"Podaj liczbe: ";
  34.     cin>>n;
  35.     cout<<"Wartosc wynosi: "<<wartosc(n)<<endl;
  36.     return 0;
  37. }
  38.  
  39. -------------------------------------------------------------------------------------
  40.  
  41. #include <iostream>
  42.  
  43. using namespace std;
  44.  
  45. long long wartosc(int n) {
  46.     if (n==1) return -2;
  47.     if (n==2) return 2;
  48.    
  49.     return wartosc(n-2)*wartosc(n-1);
  50. }
  51.  
  52. int main () {
  53.     int n;
  54.     cout<<"Podaj liczbe: ";
  55.     cin>>n;
  56.     cout<<"Wartosc wynosi: "<<wartosc(n)<<endl;
  57.     return 0;
  58. }
  59.  
  60. -------------------------------------------------------------------------------------
  61.  
  62. #include <iostream>
  63.  
  64. using namespace std;
  65.  
  66. void zamiana(int n) {
  67.     if(n>0) {
  68.         zamiana(n/2);
  69.         cout<<n%2;
  70.     }
  71. }
  72.  
  73. int main () {
  74.     int n;
  75.     cout<<"Podaj liczbe: ";
  76.     cin>>n;
  77.     cout<<"Liczba "<<n<<" w postaci binarnej to: ";
  78.     zamiana(n);
  79.     cout<<endl;
  80. }
Advertisement
Add Comment
Please, Sign In to add comment