Advertisement
JewishCat

1.4

Jan 9th, 2016
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <ctime>
  4. #include <iomanip>
  5.  
  6.  
  7. using namespace std;
  8.  
  9.  
  10. /*
  11. Дана матрица. Получить вектор, в котором содержатся максимальные элементы из каждой строки матрицы
  12. */
  13. void bol_mas(int **mas);
  14. int main()
  15. {
  16. srand(time(0)); // генерация случайных чисел
  17. int **ptrarray = new int*[10]; // две строки в массиве
  18. for (int count = 0; count < 10; count++)
  19. ptrarray[count] = new int[10]; // и пять столбцов создание динамического массива вещественных чисел на десять элементов
  20. for (int x = 0; x < 10; x++) {
  21. for (int y = 0; y < 10; y++) {
  22. ptrarray[x][y] = (rand() % 10 + 1) / float((rand() % 10 + 1));
  23. cout << setprecision(2) << ptrarray[x][y] << " ";
  24. }
  25. cout << endl;
  26. }
  27. cout << endl;
  28. bol_mas(ptrarray);
  29. for (int x = 0; x < 10; x++)
  30. delete[] ptrarray[x]; // высвобождение памяти
  31. cout << endl;
  32. system("pause");
  33. return 0;
  34. }
  35.  
  36. void bol_mas(int **mas) {
  37. int *outmas = new int[10];
  38. int buf;
  39. for (int x = 0; x < 10; x++) {
  40. buf = 0;
  41. for (int y = 0; y < 9; y++) {
  42. if (mas[x][y]>mas[x][y + 1]) {
  43. if (buf < mas[x][y]) {
  44. buf = mas[x][y];
  45. }
  46. }
  47. }
  48. outmas[x] = buf;
  49. }
  50. for (int i = 0; i < 10; i++)
  51. cout << setprecision(2) << outmas[i] << " ";
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement