Advertisement
PiotrJurek

Zad12

Apr 17th, 2020
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 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;
  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. cout << setw(3) << matrix[i][j] << " ";
  35. suma = suma + matrix[i][j];
  36. }
  37. cout << endl;
  38. }
  39. cout << "Suma elementow w macierzy: " << suma << endl;
  40. cout << "Ilosc elementow w macierzy: " << k*w << endl;
  41. cout << "Srednia elementow w macierzy: " << suma/(k*w) << endl;
  42.  
  43. return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement