C++ code to find total elements in a matrix

C++Server Side ProgrammingProgramming

Suppose, we are given a matrix of n rows and m columns. We have to find out the number of elements present in it. We find out the value and display it as output.

So, if the input is like n = 20, m = 15, then the output will be 300.

Steps

To solve this, we will follow these steps −

return n * m

Example

Let us see the following implementation to get better understanding −

#include <bits/stdc++.h>
using namespace std;
#define N 100
int solve(int n, int m) {
   return n * m;
}
int main() {
   int n = 20, m = 15;
   cout<< solve(n, m);
   return 0;
}

Input

20, 15

Output

300
raja
Updated on 29-Mar-2022 08:29:08

Advertisements