View Full Version : matrix colunms-Urgent
brad sue
Mar3-06, 12:54 PM
Hi,
Please I need help to do the following:
add the elements of each colunm of a matrix and
Count the number of colunm whose the sum is less than 1.
I did this: i is the indice of line , j =indice of colunm.. size = dimension of the square matrix.
for(j=0;j<size;j++)
{ for(i=0;i<size;i++)
{sum=sum+A[i][j];
if (sum<1)
count=count+1;}
}
The compiler says I am wrong . I have to turn this in few hours...
please help me!
Thanks
B
berkeman
Mar3-06, 01:05 PM
What do you mean the compiler "says you are wrong"? Is it throwing a syntax error?
Is sum a global or local variable? How is it initialized? How about count?
Is the assignment to come up with one sum total for all columns, or one total per column?
brad sue
Mar3-06, 01:23 PM
What do you mean the compiler "says you are wrong"? Is it throwing a syntax error?
Is sum a global or local variable? How is it initialized? How about count?
Is the assignment to come up with one sum total for all columns, or one total per column?
The compiler(Unix) say that a semicolon is missing after the second for loop. sum and count are a local variables.
In fact the assignemt says , "if the sum of each colunm ( for the whole matrix ) is less than 1 print "OK".
Example, if it is a 2 x 2 matrix,
0.2 0.25
0.3 .4
it should print "OK" since the sum of each colunm is less than 1.
This is why I use the count. if count = size ( size of the matrix) ,then each the colunm has a sum less than 1 , so I can print "OK".
sum and count are initialzed to zero at the beginning of the program.(sum=count=0;)
Thanks
You should probably post the whole code because if it is a syntax error it might have propagated from previous code. Sounds like it.
brad sue
Mar3-06, 01:35 PM
You should probably post the whole code because if it is a syntax error it might have propagated from previous code. Sounds like it.
the problem is that I am working directly in unix lab . there is no copy/paste in the editor I am using..
the problem is that I am working directly in unix lab . there is no copy/paste in the editor I am using..
That's a problem with debugging then -- many errors are simple typos. When you retype it, you're likely to get it right that time, and thus we cannot catch your typo. :frown:
berkeman
Mar3-06, 03:36 PM
the problem is that I am working directly in unix lab . there is no copy/paste in the editor I am using..
Then just pipe a listing to a file that you can post.
I am not sure if i have reached u in time
i think the syntax should be as follows
count=0;
for(j=0;j<size;j++)
{sum=0;
for(i=0;i<size;i++)
{sum=sum+A[i][j];}
if (sum<1)
count=count+1;}
vBulletin® v3.8.7, Copyright ©2000-2012, vBulletin Solutions, Inc.