Advertisement
Guest User

Untitled

a guest
Jan 17th, 2020
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.62 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <time.h>
  6. using namespace std;
  7. void zadanie1(){
  8. int tab[5][7];
  9. int sumaParzystych[5] = {0,0,0,0,0};
  10. int suma = 100;
  11. int nieparzyste = 0;
  12. for(int i = 0; i < 5; i++){
  13. for(int j = 0; j < 7; j++){
  14. tab[i][j] = suma;
  15. suma += 7;
  16. }
  17. }
  18. for(int i = 0; i < 5; i++){
  19. for(int j = 0; j < 7; j++){
  20. cout << tab[i][j] << " ";
  21. if(tab[i][j]%2 == 1){
  22. nieparzyste++;
  23. sumaParzystych[i]++;
  24. }
  25. }
  26. cout << endl;
  27. }
  28. cout << "wszystkich nieparzystych jest: " << nieparzyste << endl;
  29. for(int i = 0; i < 5; i++){
  30. cout << sumaParzystych[i] << " ";
  31. }
  32. }
  33. float oblicz(float m, float w){
  34.  
  35. return m/(w*w) * 10000;
  36.  
  37. }
  38. void zadanie2(){
  39. int m,w;
  40. cout << "aby przerwac program napisz -1" << endl << endl;
  41. while(true){
  42. cout << endl << "podaj wzrost: ";
  43. cin >> w;
  44. if(w == -1){
  45. return;
  46. }
  47. cout << "podaj mase: ";
  48. cin >> m;
  49.  
  50. cout << "Twoje BMI to: " << setprecision(3) << oblicz(m,w) << endl;
  51. }
  52. }
  53.  
  54. void randTab(int tab[5][5]){
  55. int wiersz;
  56. int sumaWiersz = 0;
  57. int kolumna1, kolumna2;
  58. int temp;
  59. for(int i = 0; i < 5; i++){
  60. for(int j = 0; j < 5; j++){
  61. tab[i][j] = rand() % 16;
  62. cout << tab[i][j] << " ";
  63. }
  64. cout << endl;
  65. }
  66.  
  67. cout << endl << "ktory wiersz chcesz zsumowac? " << endl;
  68. cin >> wiersz;
  69. cout << endl;
  70. for(int i = 0; i < 5; i++){
  71. for(int j = 0; j < 5; j++){
  72. if(i == wiersz-1){
  73. sumaWiersz += tab[i][j];
  74. }
  75. }
  76. }
  77.  
  78. cout << "suma liczb w wierszu " << wiersz << " to " << sumaWiersz << endl;
  79. cout << "podaj dwie kolumny ktore chcesz zamienic miejscami: " << endl;
  80. cin >> kolumna1;
  81. cout << endl;
  82. cin >> kolumna2;
  83. cout << endl;
  84. cout << endl;
  85. cout << "oto tablica z zamienionymi kolumnami! " << endl;
  86. for(int i = 0; i < 5; i++){
  87. for(int j = 0; j < 5; j++){
  88. if(j == kolumna1){
  89. temp = tab[i][kolumna1];
  90. tab[i][kolumna1] = tab[i][kolumna2];
  91. tab[i][kolumna2] = temp;
  92. }
  93. cout << tab[i][j] << " ";
  94. }
  95. cout << endl;
  96. }
  97. }
  98. void zadanie3(){
  99. srand (time(NULL));
  100. int tablica[5][5];
  101. randTab(tablica);
  102. }
  103. int main()
  104. {
  105. //zadanie1();
  106. //zadanie2();
  107. zadanie3();
  108. return 0;
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement