Как найти отрицательные элементы матрицы

Задача: Задача 2. Даны матрицы В (m,n) и С (n,m). Определить, есть ли в заданных матрицах столбцы, содержащие по два отрицательных элемента. Вывести номера таких столбцов. Описать функцию для анализа одного столбца.

#include <stdio.h>
#include <stdlib.h>

void input(int nlines, int mcol, int a[]) {
    int i, j;
    for (i = 0; i < nlines; i++) {
        for (j = 0; j < mcol || (puts(""), 0); j++) {
            printf("a[%d][%d] = ", i, j);
            scanf("%d", &a[i * mcol + j]);
        }
    }
    printf("n");
}

int check(int mcol, int nline, int a[]){
    int i,j;
   for (i = 0; i < mcol; i++) {
        int k = 0;
        for (j = 0; j < nline; j++) {
            if (a[i * nline + j] < 0) {
                k++;
            }
        }if(k==2){
        printf("stolb - %dn",j);
        }else{
            printf("kol-vo < or >");
        }
    }
}


int main() {
    int n,m;
    printf("Введите значение, которое будет длиной матрицы B и шириной матрицы C: ");
    scanf("%d", &n);
    printf("Введите значение, которое будет шириной матрицы B и длиной матрицы C: ");
    scanf("%d", &m);
    int b[n][m], c[m][n];
    printf("Заполните первый массив: n");
    input(n,m,&b[0][0]);
    printf("Заполните второй массив: n");
    input(n,m,&c[0][0]);
    check(n,m,&b[0][0]);   
}

Проблема в том, что программа не считает первый столбец матрицы. Если размеры матриц будут 2х2 и ввести -1,1,-1,1 и еще раз так же, то будет вывод второго принта в функции check.

A negative of a Matrix is a real or integer matrix that consists of all the elements as negative. Negative matrices are the subset of nonpositive matrices. We can get a negative of a matrix by multiplying the required matrix by −1. The negative matrix element is a negative number i.e, aij<0 for all i, j where i is the number of rows of the given matrix and j is the number of columns of the given matrix.

Learn the properties, definitions, and examples of a negative matrix. Learn all the matrices information on 10th Grade Math matrix articles on our website for free. You can easily learn all the matrices such as null matrix, Identity matrix, the addition of matrix, etc. without any confusion.

What is the Negative of a Matrix?

The Negative Matrix definition is a matrix that has all the elements negative. If we take a matrix A, then the negative of a matrix becomes -A.

A = [aij], then -A = -[aij].

Properties of a Negative Matrix

The below properties are applicable for a negative matrix. Read out the negative matrix properties before you going to solve all the problems related to the negative of a matrix.

  • In a negative matrix, all the elements of the matrix are negative i.e., a_(ij)<0 for all i, j.
  • Negative matrices are a subset of nonpositive matrices.
  • If you add a matrix with its negative matrix, then you will get a zero matrix i.e, A + (-A) = 0

Also, get

  • Properties of Addition of Matrices
  • Triangular Matrix
  • Column Matrix
  • Order of a Matrix
  • Subtraction of Two Matrices
  • Equal Matrices

Solved Examples on Negative of a Matrix

Check out the below examples to know more about the negative of a matrix. We have given a clear explanation to make your preparation easy.

Example 1. If ( A =left[
begin{matrix}
9&7 cr
5&14 cr
end{matrix}
right]
), then find the negative matrix of A.

Solution: The given matrix is ( A =left[
begin{matrix}
9&7 cr
5&14 cr
end{matrix}
right]
)
The negative matrix of A = -A.
Now by changing the signs of each element of matrix A,
we get ( A = (-1)left[
begin{matrix}
9&7 cr
5&14 cr
end{matrix}
right]
) = ( left[
begin{matrix}
-9&-7 cr
-5&-14 cr
end{matrix}
right]
)

Therefore, the negative matrix of A = -A = ( left[
begin{matrix}
-9&-7 cr
-5&-14 cr
end{matrix}
right]
)

Example 2. If ( M =left[
begin{matrix}
10&-2 cr
-6&4 cr
end{matrix}
right]
), then find the negative matrix of M.

Solution: The given matrix is ( M =left[
begin{matrix}
10&-2 cr
-6&4 cr
end{matrix}
right]
)
The negative matrix of M = -M.
Now by changing the signs of each element of matrix M,
we get ( M = (-1)left[
begin{matrix}
10&-2 cr
-6&4 cr
end{matrix}
right]
) = ( left[
begin{matrix}
-10&2 cr
6&-4 cr
end{matrix}
right]
)

Therefore, the negative matrix of M = -M = ( left[
begin{matrix}
-10&2 cr
6&-4 cr
end{matrix}
right]
)

Example 3. If ( I =left[
begin{matrix}
1&0 cr
0&1 cr
end{matrix}
right]
), then find the negative matrix of I.

Solution: The given matrix is ( I =left[
begin{matrix}
1&0 cr
0&1 cr
end{matrix}
right]
)
Now, find the negative matrix of I.
The negative matrix of I = -I.
Now by changing the signs of each element of matrix M,
we get ( I = (-1)left[
begin{matrix}
1&0 cr
0&1 cr
end{matrix}
right]
) = ( left[
begin{matrix}
-1&0 cr
0&-1 cr
end{matrix}
right]
)

Therefore, the negative matrix of I = -I = ( left[
begin{matrix}
-1&0 cr
0&-1 cr
end{matrix}
right]
)

Example 4. Find the addition of matrix A and -A is zero where ( A =left[
begin{matrix}
10&12 cr
11&13 cr
end{matrix}
right]
)

Solution: Given matrix is ( A =left[
begin{matrix}
10&12 cr
11&13 cr
end{matrix}
right]
)
Firstly find the negative of a matrix A = – A
Now by changing the signs of each element of matrix A.
negative of a matrix ( A =(-1)left[
begin{matrix}
10&12 cr
11&13 cr
end{matrix}
right]
) = ( left[
begin{matrix}
-10&-12 cr
-11&-13 cr
end{matrix}
right]
)
-A = ( left[
begin{matrix}
-10&-12 cr
-11&-13 cr
end{matrix}
right]
)
Now, add A and -A.
A + (- A) = ( left[
begin{matrix}
10&12 cr
11&13 cr
end{matrix}
right]
) + ( left[
begin{matrix}
-10&-12 cr
-11&-13 cr
end{matrix}
right]
) = ( left[
begin{matrix}
10 – 10&12 – 12 cr
11 – 11&13 – 13 cr
end{matrix}
right]
) = ( left[
begin{matrix}
0&0 cr
0&0 cr
end{matrix}
right]
)

Therefore, A + (-A) = 0.

FAQ’s on Negative of a Matrix

1. What is a Negative Matrix?

The negative matrix can be obtained by multiplying the given matrix by -1. All the elements of th negative matrix are nonpositive.

2. How to obtain a negative matrix?

Simply multiply it with the -1 to get the negative matrix.

3. What is the negative matrix for ( left[
begin{matrix}
3&-8 cr
2&-5 cr
end{matrix}
right]
)

The negative matrix of given matrix is ( left[
begin{matrix}
-3&88 cr
-2&5 cr
end{matrix}
right]
)

4. What we get by adding A and -A.

We get zero by adding A and -A. A + (-A) = 0.

Summary

The process of finding the Negative of a Matrix is explained in detail. Remember to read every concept given on our website to make your preparation efficient. You can learn any concept very easily and fast with the help of our articles.

uses
  crt;
  
var
  a: array[1..100, 1..100] of real;
  i, j, n, k, M: integer;
 
begin
  clrscr;
  n := 3;
  write('Введите число M: ');
  readln(M);
  writeln('Массив -> ');
  for i := 1 to n do
  begin
    for j := 1 to n do
    begin
      a[i, j] := cos(i * i + M);
      write(a[i, j]:8:2);
    end;
    writeln;
  end;
  k := 0;
  for i := 1 to n do 
    for j := 1 to n do
      if a[i, j] < 0 then inc(k);
  write('Всего отрицательных элементов - ', k);
  readln;
end.

#include<stdio.h>

int main()

{
const N=3,M=4;
int A[N][M],c[M],i,j,summa=0;

for (i=0; i<N; i++)
for (j=0; j<M; j++){
printf ("n A[%d,%d]:",i+1,j+1);
scanf ("%d", &A[i][j]);
}
printf("Matrix:n");
for (i=0; i<N; i++){
for (j=0; j<M; j++)
printf("%d ",A[i][j]);
printf("n");
}
for (i=0; i<M; i++) c[i]=0;
for (j=0; j<M; j++){
for (i=0; i<N; i++) if (A[i][j]>0) c[j]++;
}
for (i=0; i<M; i++) printf("In %d row: %dn",i+1,c[i]);
return 0;
}

Понравилась статья? Поделить с друзьями:

Не пропустите также:

  • Как найти устройства микротик в сети
  • Как составить акт ввода в эксплуатацию прибора учета
  • Ведьмак 2 как найти эйнара гусселя
  • Как найти объем реализации продукции в балансе
  • Как найти модуль удлинения пружины динамометра

  • 0 0 голоса
    Рейтинг статьи
    Подписаться
    Уведомить о
    guest

    0 комментариев
    Старые
    Новые Популярные
    Межтекстовые Отзывы
    Посмотреть все комментарии