Home c++ Calculate the amount of the elements of the matrix

Calculate the amount of the elements of the matrix

Author

Date

Category

It is necessary to calculate the amount of elements of each line of the matrix V (4.5) or the amount
Positive elements of the columns of this matrix at the instructions of the user.
There is a code that creates a matrix of the specified bearer and displays it (but for some reason only from positive numbers). But I do not know how to count the items and how to do it by selecting a user. If it is not difficult for you, I will be very grateful for your help.

# include & lt; iostream & gt;
# INCLUDE & LT; CTIME & GT;
Using Namespace STD;
INT MAIN ()
{
  SETLOCALE (0, "");
  SRAND (Unsigned (Time (NULL));
  int n, m;
  COUT & LT; & LT; "Enter the size of the matrix:";
  CIN & GT; & GT; N & gt; & gt; M;
  int ** a = new int * [n];
  for (int i = 0; i & lt; n; i ++)
    A [i] = new int [M];
  for (int i = 0; i & lt; n; i ++)
    for (int j = 0; j & lt; m; j ++)
      A [i] [j] = ((rand ()% 20));
 COUT & LT; & LT; "Your Matrix:" & LT; & LT; Endl & lt; & lt; Endl;
 for (int i = 0; i & lt; n; i ++)
 {
   for (int j = 0; j & lt; m; j ++)
     COUT & LT; & LT; A [i] [j] & lt; & lt; "";
   COUT & LT; & LT; Endl;
 }
 COUT & LT; & LT; Endl;
    for (int i = 0; i & lt; n; i ++)
      delete [] a [i];
    delete [] a;
}

Answer 1

Positive numbers, these are numbers that are more “0”, add a condition to this code code:

if (a [i] [j] & gt; 0)
   {
     SUM + = 1;
   }

So in the SUM variable you will receive the number of positive elements

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions