March 6, 2010

C Array

Hi ..can anyone help me please with this problem..if we have a 5x5 array and we take its numbers from the user ..how can we determine the following:
1-the largest number in the upper triangle?
2- the minimum number in the third row
3- the largest number in the second column
4- the average of numbers in the lower triangle
and thank you in advance.

I think Adam is right ;)

I think Adam is right ;)

Like  (0 likes)

Why does this sound an awful lot like a homework assignment?

Why does this sound an awful lot like a homework assignment?

Like  (0 likes)

the text from don't allow me to write such code, so use this link:...

the text from don't allow me to write such code, so use this link:

http://pastebin.com/vZ6yhhT3

I will recomendeed you first to learn how to compile a program by not using an IDE such code::block, try to compile your code from command line, see your compiler documentation. That will help you to understand about the compiler and compilation itself.. good luck!

Like  (0 likes)

Hi Ardhan Madras ..and thanks for your answer .but when i try to run this...

Hi Ardhan Madras ..and thanks for your answer .but when i try to run this program"with the Code Blocks compiler" an error message appears pointing to the statement
b=num[2]; saying that{ invalid conversion from int * to int}
so why is that? also there must be 2 loops instead of one ?

Like  (0 likes)

nope ;)

nope ;)

Like  (0 likes)

Do you means array of number (integer))? If so, perhaps your array should be...

Do you means array of number (integer))? If so, perhaps your array should be look like this in C/C++:

int num[5][5] =
{
{ -1, 12, 23, 4, 15 },
{ 16, 57, -8, 19, 0, },
{ 14, 22, -13, -14, 55 },
{ 10, 0, 2, 1, 20 },
{ 11, 22, -23, 14, 96 }
};

This is a 5x5 array of int, To determine the minimum value of 3rd row, you can use this loop:

int i, a, b;

a = num[2][0];
for (i = 1; i < 5; i++) {
b = num[2][i];
if ( a > b)
a = b;
}

after the loop end, the minimum value is now stored in a, and so with to find maximum value in a column, just change the row index and a more than '>' to less than '>'. Remember that C/C++ array always indexed from 0.

a = num[0][1];
for (i = 1; i < 5; i++) {
b = num[i][1];
if (a > b)
a = b;
}

Unfortunately i don't understand with 'triangle', but i hope this example give you a point to start.... AND I CAN'T WRITE CORRECT CODES HERE :( because it maybe re-formatted by this text-form.

Like  (0 likes)
Click Here!