Advertisement
Guest User

spr_infa_v2

a guest
Mar 20th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.42 KB | None | 0 0
  1. #include <iostream>
  2. #include <time.h>
  3. #include <math.h>
  4. #include <stdlib.h>
  5.  
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10.  
  11. /* --- ZADANIE 1A --- */
  12.  
  13. cout << "ZADANIE 1A" << endl << endl;
  14.  
  15. int a, b = 0;
  16.  
  17. cout << "Podaj 2 liczby calkowite: ";
  18. cin >> a >> b;
  19.  
  20. switch(a)
  21. {
  22. case 12:
  23. cout << "Podano liczbe 12, a druga liczba to: " << b;
  24. break;
  25. case -12:
  26. cout << "Kwadrat drugiej liczby: " << b * b;
  27. break;
  28. case 15:
  29. cout << "Druga liczba podzielona przez 5: " << (float)b / 5.0;
  30. break;
  31. case 22:
  32. {
  33. error:
  34. if(b < 0)
  35. {
  36. cout << "Podaj ponownie 2 liczbe (taka aby byla >= 0): ";
  37. cin >> b;
  38. goto error;
  39. }
  40. cout << "Pierwiastek z drugiej liczby: " << sqrt(b);
  41. break;
  42. }
  43. case -24:
  44. cout << "Srednia z obu liczb: " << (float)(a + b) / 2.0;
  45. break;
  46. default:
  47. cout << "nieprawidlowy wybor";
  48. }
  49.  
  50. cout << endl;
  51.  
  52.  
  53. /* --- ZADANIE 1B --- */
  54.  
  55. cout << endl << "ZADANIE 1B" << endl << endl;
  56.  
  57. for(int i = 10; i <= 21; i++)
  58. {
  59. cout.width( 4 );
  60. cout << i;
  61. }
  62.  
  63. cout << endl << endl;
  64.  
  65. for(int i = 45; i >= -15; i-=5)
  66. {
  67. cout.width( 4 );
  68. cout << i;
  69. }
  70.  
  71. cout << endl << endl;
  72.  
  73. for(int i = 1; i <= 9; i++)
  74. {
  75. for(int a = 1; a <= 11; a++)
  76. {
  77. cout.width( 4 );
  78. cout << a * i;
  79. }
  80. cout << endl;
  81. }
  82.  
  83. cout << endl << endl;
  84.  
  85. for(int i = 9; i >= 2; i--)
  86. {
  87. for(int a = 7; a >= 2; a--)
  88. {
  89. cout.width( 4 );
  90. cout << a * i;
  91. }
  92. cout << endl;
  93. }
  94.  
  95.  
  96.  
  97. /* --- ZADANIE 2A --- */
  98.  
  99. cout << endl << "ZADANIE 2A" << endl << endl;
  100.  
  101. double A;
  102.  
  103. cout << "Podaj liczbe A (double): ";
  104. cin >> A;
  105.  
  106. PK_1:
  107.  
  108. if(A > 0)
  109. {
  110. A /= 10;
  111. if(A < 8)
  112. {
  113. A += 12;
  114. PK_3:
  115. if(A < 50)
  116. {
  117. cout << "Liczba A: " << A << endl;
  118. goto the_end;
  119. }
  120. else
  121. {
  122. goto PK_1;
  123. }
  124. }
  125. else
  126. {
  127. A -= 20;
  128. goto PK_1;
  129. }
  130. }
  131. else
  132. {
  133. PK_2:
  134. A += 10;
  135. if(A < 20)
  136. {
  137. goto PK_2;
  138. }
  139. else
  140. {
  141. A /= 3;
  142. goto PK_3;
  143. }
  144. }
  145.  
  146. the_end:
  147. // Wyjscie z programu po wyswietleniu liczy A
  148. // return 0;
  149.  
  150.  
  151. /* --- ZADANIE 2B --- */
  152.  
  153. cout << endl << "ZADANIE 2B" << endl << endl;
  154.  
  155. srand(time(NULL));
  156.  
  157. for(int i = 0; i < 10; i++)
  158. {
  159. cout << rand() % 10 + 1 << " ";
  160. }
  161. cout << endl << endl;
  162.  
  163. for(int i = 0; i < 10; i++)
  164. {
  165. cout << rand() % 501 - 200 << " ";
  166. }
  167. cout << endl << endl;
  168.  
  169. for(int i = 0; i < 10; i++)
  170. {
  171. comeback:
  172. int a = rand() % 101 - 60;
  173. if (a % 4 == 0)
  174. cout << a << " ";
  175. else
  176. goto comeback;
  177. }
  178. cout << endl << endl;
  179.  
  180. for(int i = 0; i < 10; i++)
  181. {
  182. float f = (rand() % 301) / 10.0;
  183. f -= 15.0;
  184.  
  185. cout << f << " ";
  186. }
  187. cout << endl << endl;
  188.  
  189.  
  190.  
  191. return 0;
  192. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement