JakubKaczmarek_123

wskaźniki - zadania

Apr 16th, 2021
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.69 KB | None | 0 0
  1. ZADANIE 1
  2.  
  3. #include <iostream>
  4.  
  5. using namespace std;
  6. int a = 15;
  7. int main(){
  8. cout << "wartosc przypisana do zmiennej: " << a << endl;
  9. cout << "adres w pamieci tej zmiennej: " << (intptr_t)&a << endl;
  10. }
  11.  
  12. ZADANIE 2
  13.  
  14. #include <iostream>
  15.  
  16. using namespace std;
  17. int b = 20;
  18. int *a = &b;
  19. int main(){
  20. cout << "wartosc b: " << b << endl;
  21. cout << "adres b: " << (intptr_t)a << endl;
  22. cout << "adres wskaznika a: " << (intptr_t)&a << endl;
  23. cout << "wartosc wskaznika a: " << *a << endl;
  24. }
  25.  
  26.  
  27. ZADANIE 3
  28.  
  29. #include <iostream>
  30.  
  31. using namespace std;
  32. int a = 14;
  33. float b = 6.7;
  34. char c = 'x';
  35. int *w_a = &a;
  36. float *w_b = &b;
  37. char *w_c = &c;
  38. int main(){
  39. cout << "a: " << a << endl;
  40. cout << "b: " << b << endl;
  41. cout << "c: " << c << endl;
  42. cout << "adres a: " << (intptr_t)&a << endl;
  43. cout << "adres b: " << (intptr_t)&b << endl;
  44. cout << "adres c: " << (intptr_t)&c << endl;
  45. cout << "wartosc adresu a: " << *w_a << endl;
  46. cout << "wartosc adresu b: " << *w_b << endl;
  47. cout << "wartosc adresu c: " << *w_c << endl;
  48. }
  49.  
  50.  
  51. ZADANIE 4
  52.  
  53. #include <iostream>
  54.  
  55. using namespace std;
  56. int a = 6;
  57. int b = 8;
  58. int *w_a = &a;
  59. int *w_b = &b;
  60. int main(){
  61. cout << "suma: " << *w_a + *w_b << endl;
  62. }
  63.  
  64. ZADANIE 5
  65.  
  66. #include <iostream>
  67.  
  68. using namespace std;
  69. int a = 6;
  70. int b = 8;
  71. int *w_a = &a;
  72. int *w_b = &b;
  73. int main(){
  74. cout << "iloczyn: " << *w_a * *w_b << endl;
  75. }
  76.  
  77. ZADANIE 6
  78.  
  79. #include <iostream>
  80.  
  81. using namespace std;
  82. int suma(int *a, int *b);
  83. int a = 6;
  84. int b = 8;
  85. int *w_a = &a;
  86. int *w_b = &b;
  87. int main(){
  88. cout << "suma wynosi: " << suma(w_a, w_b)<< endl;
  89. }
  90.  
  91. int suma(int *a, int *b){
  92. return *a + *b;
  93. }
  94.  
  95. ZADANIE 7
  96.  
  97. #include <iostream>
  98. #include <math.h>
  99. using namespace std;
  100. float pole(int *r);
  101. int r = 8;
  102. int *w_r = &r;
  103. int main(){
  104. cout << "pole kola wynosi: " << pole(w_r)<< endl;
  105. }
  106.  
  107. float pole(int *r){
  108. return *r * *r * M_PI;
  109. }
  110.  
  111. ZADANIE 8
  112.  
  113. #include <iostream>
  114.  
  115. using namespace std;
  116.  
  117.  
  118. int a = 45;
  119. int b = 44;
  120. int *w_a = &a;
  121. int *w_b = &b;
  122.  
  123. int main(){
  124. if (*w_a > *w_b) cout << "Liczba 45 jest wieksza od 44" << endl;
  125. else cout << "Liczba 44 jest wieksza od 45" << endl;
  126. }
  127.  
  128. ZADANIE 9
  129.  
  130. #include <iostream>
  131.  
  132. using namespace std;
  133. int silnia(int *w_a);
  134. int a = 6;
  135. int *w_a = &a;
  136.  
  137.  
  138. int main(){
  139. cout << "Silnia z 6 wynosi: " << silnia(w_a) << endl;
  140. }
  141. int silnia(int *w_a){
  142.    int b = 1;
  143.    for (int i = 1; i < *w_a+1; i++) b*=i;
  144.    return b;
  145. }
  146.  
  147. ZADANIE 10
  148.  
  149. #include <iostream>
  150.  
  151. using namespace std;
  152. int suma(int *w_a);
  153. int a[] = {8, 6, 2, 6};
  154. int *w_a = a;
  155.  
  156.  
  157. int main(){
  158. cout << "Suma wartosci elementow z tablicy wynosi: " << suma(w_a) << endl;
  159. }
  160. int suma(int *w_a){
  161.     int b = 0;
  162.     for (int i = 0; i < 4; i++) b+=*(w_a+i);
  163.     return b;
  164. }
Advertisement
Add Comment
Please, Sign In to add comment