Advertisement
bartkoo

zadania wskaźniki

Apr 16th, 2021
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.91 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. using namespace std;
  5.  
  6. void cw_1();
  7. void cw_2();
  8. void cw_3();
  9. void cw_4();
  10. void cw_5();
  11.  
  12. void cw_6(int *sum, int *a, int *b);
  13. int cw_6(int *a, int *b);
  14.  
  15. void cw_7(float *area, float r);
  16. float cw_7(float *r);
  17.  
  18. string cw_8(int *a, int *b);
  19. int cw_9(int *a);
  20.  
  21. int cw_10(int *tab, int *size);
  22.  
  23. int main()
  24. {
  25.     cw_1();
  26.     cout<<"..."<<endl;
  27.     cw_2();
  28.     cout<<"..."<<endl;
  29.     cw_3();
  30.     cout<<"..."<<endl;
  31.     cw_4();
  32.     cout<<"..."<<endl;
  33.     cw_5();
  34.     cout<<"..."<<endl;
  35.     int sum = 0, a = 6, b=15;
  36.     cw_6(&sum, &a, &b);
  37.     cout<<sum<<endl;
  38.     cout<<cw_6(&a, &b)<<endl;
  39.     cout<<"..."<<endl;
  40.     float area = 0, r = 8;
  41.     cw_7(&area, r);
  42.     cout<<area<<endl;
  43.     cout<<cw_7(&r)<<endl;
  44.     cout<<"..."<<endl;
  45.     int a_8=45, b_8=44;
  46.     cout<<cw_8(&a_8, &b_8)<<endl;
  47.     cout<<"..."<<endl;
  48.     int a_9 = 6;
  49.     cout<<"Silnia z "<<a_9<<" wynosi : "<<cw_9(&a_9)<<endl;
  50.     cout<<"..."<<endl;
  51.     int tab[] = {8, 6, 2, 6}, size = 4;
  52.     cout<<"Suma wartosci elementow z tablicy wynosi: "<<cw_10(tab, &size)<<endl;
  53.    
  54.     return 0;
  55. }
  56.  
  57. void cw_1(){
  58.     int a = 15;
  59.     cout<<a<<endl;
  60.     cout<<(intptr_t)&a<<endl;
  61. }
  62.  
  63. void cw_2(){
  64.     int *a, b=20;
  65.     cout<<(intptr_t)&b<<endl;
  66.     cout<<b<<endl;
  67.     a = &b;
  68.     cout<<(intptr_t)&a<<endl;
  69.     cout<<(intptr_t)a<<endl;
  70.     cout<<*a<<endl;
  71. }
  72.  
  73. void cw_3(){
  74.     int a=14, *w_a = &a;
  75.     float b=6.7, *w_b = &b;
  76.     char c='x', *w_c = &c;
  77.  
  78.     cout<<"a = "<<a<<endl;
  79.     cout<<"b = "<<b<<endl;
  80.     cout<<"c = "<<c<<endl;
  81.  
  82.     cout<<"Adres a = "<<(intptr_t)&a<<endl;
  83.     cout<<"Adres b = "<<(intptr_t)&b<<endl;
  84.     cout<<"Adres c = "<<(intptr_t)&c<<endl;
  85.  
  86.     cout<<"Wartosc sadresu a = "<<*w_a<<endl;
  87.     cout<<"Wartosc sadresu b = "<<*w_b<<endl;
  88.     cout<<"Wartosc sadresu c = "<<*w_c<<endl;
  89. }
  90.  
  91. void cw_4(){
  92.     int a=6, b=8;
  93.     int *w_a = &a, *w_b = &b;
  94.     cout<<*w_a + *w_b<<endl;
  95. }
  96.  
  97. void cw_5(){
  98.     int a=6, b=9;
  99.     int *w_a = &a, *w_b = &b;
  100.     cout<<*w_a * *w_b<<endl;
  101. }
  102.  
  103. void cw_6(int *sum, int *a, int *b){
  104.     *sum = *a + *b;
  105. }
  106.  
  107. int cw_6(int *a, int *b){
  108.     return *a + *b;
  109. }
  110.  
  111. void cw_7(float *area, float r){
  112.     *area = M_PI * r * r;
  113. }
  114.  
  115. float cw_7(float *r){
  116.     return M_PI * *r * *r;
  117. }
  118.  
  119. string cw_8(int *a, int *b){
  120.     string result;
  121.     if(*a > *b){
  122.         result = "Liczba " + to_string(*a) + " jest wieksza od " + to_string(*b);
  123.     } else if(*b > *a){
  124.         result = "Liczba " + to_string(*b) + " jest wieksza od " + to_string(*a);
  125.     }else{
  126.         result = "Liczby sa sobie rowne";
  127.     }
  128.     return result;
  129. }
  130.  
  131. int cw_9(int *a){
  132.     if(*a == 0) return 1;
  133.     else{
  134.         //*a -= 1;
  135.         (*a)--;
  136.         return (*a+1) * cw_9(a);
  137.     }
  138. }
  139.  
  140. int cw_10(int *tab, int *size){
  141.     int sum = 0;
  142.     int iterator = 0;
  143.     for(int *i=&iterator; *i<*size; (*i)++){
  144.         sum += *(tab+*i);
  145.     }
  146.     return sum;
  147. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement