C++ code to find total elements in a matrix


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

Updated on: 29-Mar-2022

149 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements