English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

i've made this prog but it is not printing the correct output. plzzz help
#include
#include
void main()
{
clrscr();
int a[3][3],max,min;
cout<<"enter the matrix: ";
for(int i=0;i<3;i++)
{ for(int j=0;j<3;j++)
{ cin>>a[i][i]; }
}
max=a[0][0];
min=a[0][0];
for(i=0;i<3;i++)
{ for(int j=0;j<3;j++)
{ if(a[i][j] min=a[i][j];
if(a[i][j]>max)
max=a[i][j];
}
}
cout<<"the max character is: "< getch();
}

2007-01-05 19:22:14 · 2 answers · asked by Anonymous in Computers & Internet Programming & Design

2 answers

the line
{cin >>a[i][i];}

should read
{cin >>a[i][j];}

In the part where you are entering the matrix. Otherwise you are just reading into the diagonals of the matrix and leaving the off-diagonals empty.

2007-01-05 19:31:16 · answer #1 · answered by days_o_work 4 · 1 0

You need to print out the matrix, but I don't see that anywhere.

Within your two nested for loops, you need to add a cout statement (or two.) The first would be immediately after the second for and would be something like:

cout << " " << a[i][j];

the next would be between the two braces after the max= line and it would look like:
cout << endl;

This prints the item in each matrix position while you're searching for the largest number.

Also, initialize max and min to 0, not a[0][0]

It looks like you're reading data into a[i][i]... that should be a[i][j], right?

2007-01-05 19:32:46 · answer #2 · answered by BigRez 6 · 0 0

fedest.com, questions and answers