Hi , i wrote this code it suppose to multiply two 3X3 matrix
and it works but now i want to make it with a function and im really noob
can anyone help me please or give me some advice thanks alot
Do you know what version of the C++ standards you are compiling to?
What part or parts do you want in functions?
"iostream.h" is a very old file that is no longer used. I am not good at history, but I am thinking it is pre-1998 standards or through the '98 standards.
I have reworked your code. This works with the 2011 standards.
#include <iostream>
int main()
{
constexprint MAXROW{ 3 }, MAXCOL{ 3 };
int a[MAXROW][MAXCOL]{}, b[MAXROW][MAXCOL]{}, c[MAXROW][MAXCOL]{};
int sum{};
std::cout << "matris e aval ro vared kon";
for (int p = 0; p < MAXROW; p++)
{
for (int q = 0; q < MAXCOL; q++)
{
std::cin >> a[p][q];
}
}
std::cout << "matris e dovom ro vared kon";
for (int p = 0; p < MAXROW; p++)
{
for (int q = 0; q < MAXCOL; q++)
{
std::cin >> b[p][q];
}
}
for (int p = 0; p <= 2; p++)
{
for (int q = 0; q <= 2; q++)
{
sum = 0;
for (int x = 0; x <= 2; x++)
{
sum = sum + a[p][x] * b[x][q];
}
c[p][q] = sum;
}
}
std::cout << '\n' << "zarbe matris ha=" << std::endl;
for (int p = 0; p < MAXROW; p++)
for (int q = 0; q < MAXCOL; q++)
{
std::cout << " " << c[p][q];
}
return 0;
}
The blank lines I added make the code easier to read. Also I find the use of the {}s work better, but you are free to choose whatever form you like or have learned.
One last note: Since you "cout" statements are in a language other than English, mention what your native language is so translations can be done correctly with out having to guess.