Good Day guys, I wanted to make a multiplication table but it seems not that easy for a newbie like me. Mind taking your time and see what I am missing in my code? It would be a great help. Here's the code:

#include<iostream>
#include<conio.h>
using namespace std;

void initArray(int arg1[50][50], int r, int c)
{
     int val=1;
     for(int row=0; row<r; row++)
     {
             for(int col=0; col<c; col++)
             {
             arg1[row][col]=val;
             val++;
             }
     }
}

void mulTable(int arg1[50][50], int r, int c)
{
        for(int row=0; row<r; row++)
        {
        int mul=0;
              for(int col=0; col<c; col++)
              {
              mul = mul * arg1[row][col];
              cout << mul << " ";
              }
    }
}


int main(){
    int arr1[50][50], val=1;
    int row = 0, col = 0;

        cout <<" Enter number of Row: ";
        cin >>row;
        cout <<"Enter number of Column: ";
        cin >> col;

initArray(arr1,row,col);
mulTable(arr1,row,col);


getch();
return 0;
}

I want the output to be like this:
1 2 3
2 4 6
3 6 9
If the user inputs 3 rows and 3 columns. Thank you. :)

Recommended Answers

All 2 Replies

On line 22 of your code I should definitly try int mul=1 instead of int mul=0

Also, I think you are passing the array in by value (copy) so it won't be visible outside of the function. You need to pass by reference as in:
void mulTable(int (&arg1)[50][50], int r, int c)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.