PiotrJurek

Zad14

Apr 17th, 2020
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <ctime>
  4. #include <windows.h>
  5. #include <iomanip>
  6.  
  7. using namespace std;
  8.  
  9. int main()
  10. {
  11. int w, k, x;
  12. int suma = 0;
  13. do
  14. {
  15. cout << "Ile wierszy:" << endl;
  16. cin >> w;
  17. system("cls");
  18. }
  19. while(w<1);
  20. do
  21. {
  22. cout << "Ile kolumn:" << endl;
  23. cin >> k;
  24. system("cls");
  25. }
  26. while(k<1);
  27. int matrix[w][k];
  28. srand(time(NULL));
  29. for(int i=0; i<w; i++)
  30. {
  31. for(int j=0; j<k; j++)
  32. {
  33. matrix[i][j]=rand()%100+1;
  34. }
  35. }
  36. do
  37. {
  38. cout << "Ktory wiersz macierzy chcesz zsumowac:" << endl;
  39. cin >> x;
  40. system("cls");
  41. }
  42. while(x>w || x<1);
  43. cout << "MACIERZ:" << endl;
  44. for(int i=0; i<w; i++)
  45. {
  46. for(int j=0; j<k; j++)
  47. {
  48. cout << setw(3) << matrix[i][j] << " ";
  49. }
  50. cout << endl;
  51. }
  52. for(int j=0; j<k; j++)
  53. {
  54. suma = suma + matrix[x-1][j];
  55. }
  56. cout << "Suma liczb w wierszu nr: " << x << " wynosi: " << suma << endl;
  57.  
  58. return 0;
  59. }
Add Comment
Please, Sign In to add comment