Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 1.
- #define _CRT_SECURE_NO_WARNINGS
- #include <stdio.h>
- #include <stdlib.h>
- #include <conio.h>
- #include <ctime>
- void fill_array(int **a, int h, int w)
- {
- for(unsigned int k = 0; k < w; k++)
- for (unsigned int j = 0; j < h; j++)
- {
- a[k][j] = (rand() % 40) + 11;
- }
- }
- void print_array(int **a, int h, int w)
- {
- for (unsigned int k = 0; k < w; k++)
- {
- printf("\n");
- for (unsigned int j = 0; j < h; j++)
- {
- printf("%d\t", a[k][j]);
- }
- }
- }
- int main()
- {
- srand(time(0));
- int h, w;
- printf("input height and weight of array:\n");
- scanf("%d %d", &h, &w);
- int **a = new int*[w];
- for (unsigned int i = 0; i < w; i++)
- {
- a[i] = new int[h];
- }
- fill_array(a, h, w);
- print_array(a, h, w);
- for (int j = 0; j < h; j++)
- delete[]a[j];
- system("pause");
- return 0;
- }
- 2.
- #define _CRT_SECURE_NO_WARNINGS
- #include <stdio.h>
- #include <stdlib.h>
- #include <conio.h>
- #include <ctime>
- //Заполнение массива
- void fill_array(int a[5][5])
- {
- for (unsigned int k = 0; k < 5; k++)
- for (unsigned int j = 0; j < 5; j++)
- {
- a[k][j] = (rand() % 80) + 10;
- }
- }
- //Сортировка по максимальному элементу
- void regulation(int a[5][5])
- {
- for (unsigned int k = 0; k < 5; k++)
- {
- int* max = &a[k][0];
- for (unsigned int j = 0; j < 5; j++)
- {
- if (a[k][j] > *max)
- {
- max = &a[k][j];
- }
- }
- int helper = a[k][0];
- a[k][0] = *max;
- *max = helper;
- }
- }
- //Вывод текущей матрицы
- void print_array(int a[5][5])
- {
- for (unsigned int k = 0; k < 5; k++)
- {
- printf("\n");
- for (unsigned int j = 0; j < 5; j++)
- {
- printf("%d\t", a[k][j]);
- }
- }
- printf("\n\n");
- }
- int main()
- {
- //Начальные данные
- srand(time(0));
- int a[5][5];
- fill_array(a);
- print_array(a);
- //Обработка
- regulation(a);
- print_array(a);
- //
- system("pause");
- return 0;
- }
- 3.
- #define _CRT_SECURE_NO_WARNINGS
- #include <stdio.h>
- #include <stdlib.h>
- #include <conio.h>
- #include <ctime>
- //Заполнение массива
- void fill_array(int **a, int h, int w)
- {
- for (unsigned int k = 0; k < w; k++)
- for (unsigned int j = 0; j < h; j++)
- {
- a[k][j] = (rand() % 9) + 1;
- }
- }
- //Вывод текущей матрицы
- void print_array(int **a, int h, int w)
- {
- for (unsigned int k = 0; k < w; k++)
- {
- printf("\n");
- for (unsigned int j = 0; j < h; j++)
- {
- printf("%d\t", a[k][j]);
- }
- }
- printf("\n");
- }
- void multiply_arrays(int **firstArray, int firstWitdh, int firstHeight, int **secondArray, int secondWitdh, int secondHeight, int **newArray)
- {
- for (unsigned int i = 0; i < firstWitdh; i++)
- for (unsigned k = 0; k < secondHeight; k++)
- {
- int summ = 0;
- for (int j = 0; j < firstHeight; j++)
- {
- summ += firstArray[i][j] * secondArray[j][k];
- }
- newArray[i][k] = summ;
- }
- }
- /*
- for (int i = 0; i < 4; i++) a[4][3] x b[3][5]
- for (int k = 0; k < 5; k++)
- {
- int summ = 0;
- for (int j = 0; j < 3; j++)
- {
- summ += a[i][j] * b[j][k];
- }
- c[i][k] = summ;
- }
- */
- int main()
- {
- //Начальные данные
- srand(time(0));
- int w1, h1, w2, h2;
- printf("input width and heights:\n");
- scanf("%d %d %d %d", &w1, &h1, &w2, &h2);
- int **a = new int*[w1];
- for (unsigned int i = 0; i < w1; i++)
- {
- a[i] = new int[h1];
- }
- int **b = new int*[w2];
- for (unsigned int i = 0; i < w2; i++)
- {
- b[i] = new int[h2];
- }
- int **c = new int*[w1];
- for (unsigned int i = 0; i < w1; i++)
- {
- c[i] = new int[h2];
- }
- fill_array(a, h1, w1);
- fill_array(b, h2, w2);
- print_array(a, h1, w1);
- print_array(b, h2, w2);
- //
- //Обработка
- multiply_arrays(a, w1, h1, b, w2, h2, c);
- print_array(c, h2, w1);
- //завершение
- for (int j = 0; j < w1; j++)
- delete[]a[j];
- for (int j = 0; j < w2; j++)
- delete[]b[j];
- for (int j = 0; j < w1; j++)
- delete[]c[j];
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement