Advertisement
Zennoma

ksinus

Feb 29th, 2020
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. динамическая память целочисленная н на м, среднее арифметическое столбца и на последнее место последнего столбца вывести адреса
  2. //последних жлементов у столбцов, вывести исход, полученную ит найденные средние
  3. #include <stdlib.h>
  4. #include <stdio.h>
  5. #include<time.h>
  6.  
  7. int main()
  8. {
  9. srand(time(NULL));
  10. int n, m;
  11. puts("inputed row number");
  12. scanf_s("%d", &n);
  13. int** array = new int* [n]; // Создаем массив указателей
  14. puts("input collums number");
  15. scanf_s("%d", &m);
  16. puts("generated matrix");
  17. for (int i = 0; i < n; i++)
  18. {
  19. array[i] = new int[m]; // Создаем элементы
  20. }
  21. for (int i = 0; i < n; i++)
  22. {
  23. for (int j = 0; j < m; j++)
  24. {
  25. *(*(array + i) + j) = rand() % 21 - 10;
  26. printf_s("%6d", *(*(array + i) + j));
  27. }
  28. printf_s("\n");
  29. }
  30.  
  31.  
  32. // ОСНОВНАЯ ПРОГРАММА
  33. for (int i = 0; i < m; i++) //нахождение адресов и смена мест
  34. {
  35. int schet=0;
  36. int count = 0;
  37. int sred = 0;
  38. for (int j = 0; j < n; j++)
  39. {
  40. schet += *(*(array + j) + i);
  41. count++;
  42. }
  43. sred = schet / count;
  44. *(*(array+n-1)+i) = sred;
  45. }
  46.  
  47.  
  48.  
  49. // Печать новой матрицы
  50. puts("new matrix");
  51. for (int i = 0; i < n; i++)
  52. {
  53. for (int j = 0; j < m; j++)
  54. {
  55. printf_s("%6d", *(*(array + i) + j));
  56. }
  57. printf_s("\n");
  58. }
  59. puts("adress last elem");
  60. int i = n - 1;
  61. for (int j = 0; j < m; j++)
  62. {
  63. printf_s("%6p\n", array + i + j);
  64. }
  65. // Удаление массива
  66. /*for (int i = 0; i < n; i++)
  67. {
  68. delete[]array[i]; // Удаляем каждый элемент
  69. }
  70. delete[] array; // А потом массив*/
  71. return 0;
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement