Forums: » Register « |  Free Tools |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |

New Free Tools on Dev Shed!

#1
November 16th, 2012, 04:37 PM
 mnkjoi
Registered User

Join Date: Nov 2012
Posts: 8
Time spent in forums: 49 m 24 sec
Reputation Power: 0
Help with multi-diemensional array

Hello,

I have a problem with the following code

int main()
{
int i,j,max;
int a[3][3]={{85,99,77},
{80,73,74},
{89,33,88}};

for (i=0;i<3;i++){
max=0;
printf (" \n");
for (j=0;j<3;j++)
if (max<a[i][j])
max=a[i][j];
printf ("%d the maximum is %i ",a[i][j],max);
}
}

I want the output to be the ALL numbers in arrays and the maximum number of each row I tried and tried but I couldn't know where is the problem,and here is the output
80 the maximum is 99
89 the maximum is 80
0 the maximum is 99

any help pls

#2
November 16th, 2012, 04:49 PM
 G4143
Contributing User

Join Date: Oct 2012
Posts: 71
Time spent in forums: 1 Day 7 h 39 m 39 sec
Reputation Power: 2
You could try posting nicely formated code like below...

Code:
```#include <stdio.h>

int main()
{
int i, j, max;

int a[3][3]={{85,99,77}, {80,73,74}, {89,33,88}};

for (i= 0; i < 3; i++)
{
max=0;
printf (" \n");

for (j=0;j<3;j++)
{
if (max < a[i][j])
max = a[i][j];

printf ("%d the maximum is %i\n",a[i][j],max);
}
fputs("\n", stdout);
}

return 0;
}```

The output of the above code is...

Code:
```85 the maximum is 85
99 the maximum is 99
77 the maximum is 99

80 the maximum is 80
73 the maximum is 80
74 the maximum is 80

89 the maximum is 89
33 the maximum is 89
88 the maximum is 89```

#3
November 16th, 2012, 04:51 PM
 bdb
Contributing User

Join Date: Aug 2012
Posts: 156
Time spent in forums: 1 Week 15 h 48 m 11 sec
Reputation Power: 33
Quote:
 printf ("%d the maximum is %i ",a[i][j],max);

Print i and j too
Code:
`printf ("%d the maximum is %i (i is %d; j is %d)\n", a[i][j], max, i, j);`

#4
November 17th, 2012, 03:32 AM
 mnkjoi
Registered User

Join Date: Nov 2012
Posts: 8
Time spent in forums: 49 m 24 sec
Reputation Power: 0
thank you very much

 Viewing: Dev Shed Forums > Programming Languages > C Programming > Help with multi-diemensional array