Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <locale.h>
- const char* intTab = "%4d";
- const char* charTab = "%4c";
- const char deleteChar = '#';
- const int height = 2;
- const int width = 2;
- int main() {
- char* locale = setlocale(LC_ALL, "");
- int matrix[height][width];
- int newMatrix[height - 1][width - 1];
- int countNegative = 0, maxCountNegative = 0, indexNegative = 0;
- int countPositive = 0, maxCountPositive = 0, indexPositive = 0;
- if (height < 2 || width > 2 || height > 100 || width > 100)
- printf("Некорректный размер матрицы\n");
- else
- {
- printf("Исходная матрица\n");
- for (int i = 0; i < height; i++) {
- printf("\n");
- for (int j = 0; j < width; j++) {
- matrix[i][j] = rand() % 18 - 9;
- printf(intTab, matrix[i][j]);
- }
- }
- for (int i = 0; i < height; i++) {
- countNegative = 0;
- for (int j = 0; j < width; j++)
- if (matrix[i][j] < 0)
- countNegative++;
- if (maxCountNegative < countNegative) {
- indexNegative = i;
- maxCountNegative = countNegative;
- }
- }
- for (int i = 0; i < width; i++) {
- countPositive = 0;
- for (int j = 0; j < height; j++)
- if (matrix[j][i] > 0)
- countPositive++;
- if (maxCountPositive < countPositive) {
- indexPositive = i;
- maxCountPositive = countPositive;
- }
- }
- if (maxCountNegative == 0 || maxCountPositive == 0)
- {
- printf("\r\nВ матрице отсутствуют отрицательные либо положительные элементы");
- }
- else
- {
- printf("\n\nСтрока и столбец для удаления:");
- for (int i = 0; i < height; i++) {
- printf("\n");
- for (int j = 0; j < width; j++)
- if (i == indexNegative || j == indexPositive)
- printf(charTab, deleteChar);
- else
- printf(intTab, matrix[i][j]);
- }
- for (int i = 0; i < height; i++) {
- for (int j = 0; j < width; j++) {
- if ((i < indexNegative) && (j < indexPositive))
- newMatrix[i][j] = matrix[i][j];
- else if ((i > indexNegative) && (j < indexPositive))
- newMatrix[i - 1][j] = matrix[i][j];
- else if ((i < indexNegative) && (j > indexPositive))
- newMatrix[i][j - 1] = matrix[i][j];
- else if ((i > indexNegative) && (j > indexPositive))
- newMatrix[i - 1][j - 1] = matrix[i][j];
- }
- }
- printf("\n\nМатрица после удаления");
- for (int i = 0; i < height - 1; i++) {
- printf("\n");
- for (int j = 0; j < width - 1; j++)
- printf(intTab, newMatrix[i][j]);
- }
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement