Hello everyone!

I need a C++ program that stores the results of product table from 1 to 10 in two-dimensional array...


what i did :

#include<iostream.h>
void main()
{
int a[5][2],result;
const int k=1;
for(int f=1;f<=10;f++)
 result=k*f;
for(int i=0;i<5;i++)
{
for(int j=0;j<2;j++)
{
a[i][j]=result;
cout<<"a["<<i<<"]["<<j<<"]="<<a[i][j]<<endl;
}
}
}

BUT the output was:
10
10
10
10
10
10
10
10
10
10

I'm pretty sure there's something missing in the code...could u plz help?

result is set to 10 in the last iteration of the first for loop

and then you assign result (10) to every element of your 2-d array in the other for loops

At line 7 when the loop ends, f will be 10. You are simply multiplying 1*10 and storing it in result. You can make result an array of size 10 then use

result[f-1]=k*f;

At line 7 when the loop ends, f will be 10. You are simply multiplying 1*10 and storing it in result. You can make result an array of size 10 then use

result[f-1]=k*f;

many thnx

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.