Member Avatar for kohkohkoh

here is the question:
Use a two-dimensional array called price to hold the prices for Proton’s car
regarding to the models and CC as listed below.

--------------------------------------------------------------------------
in 2d array..i could get
(for example)
void disp(a[][3]);
int main()
{
num[3][2] = { {1,2},{4,5},{7,8} }
disp(num);
return 0;
}
void disp(a[][3])
{
for (int i=1; i<=3 ; i++)
for (int i=1; i<=2 ; i++)
cout << a[j] << endl;
}
--------------------------------------------------------------------------
my question is:
how do i seperate the i and j so i could form like a table..
something like this:
model price
i j
i+1 j+1
i+2 j+2
.....and so on..
instead of
1 2
4 5
7 8
All i want is to spread i and j wide....
p.s Get what i mean??

Hi everyone,

Do not use a nested loop but just use a single input variable with a counter like variable

Try this

int k=0;
for(i = 0;i<3;i++)
{
k = k+1;
j = i;
printf("%d "a[i+k][j+k])
}

I hope you this helps you

Yours sincerely

Richard West

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.