Efficient Matrix Column Sum and Count: Solve Urgent Deadline in Hours

  • Thread starter Thread starter brad sue
  • Start date Start date
  • Tags Tags
    Matrix
Click For Summary

Discussion Overview

The discussion revolves around a programming problem related to calculating the sum of each column in a matrix and counting how many columns have a sum less than 1. The context includes debugging issues and syntax errors encountered while coding in a Unix environment.

Discussion Character

  • Homework-related
  • Technical explanation
  • Debate/contested

Main Points Raised

  • One participant requests help with a coding task involving matrix column sums and counting columns with sums less than 1.
  • Several participants inquire about the nature of the compiler error, asking if it is a syntax error and the initialization of variables.
  • A participant clarifies that the assignment requires checking each column's sum individually and printing "OK" if all sums are less than 1.
  • Another participant suggests posting the entire code to identify potential syntax errors that may have propagated from earlier code.
  • One participant notes the difficulty of debugging in a Unix lab environment without copy/paste functionality, which may lead to simple typos.
  • A later reply proposes a revised code structure that initializes the sum to zero for each column before summing its elements.

Areas of Agreement / Disagreement

Participants express varying degrees of understanding regarding the problem and the coding approach. There is no consensus on the exact nature of the errors or the best way to resolve them, as multiple suggestions and clarifications are offered.

Contextual Notes

Limitations include the potential for syntax errors due to typos, the lack of visibility into the entire code, and the constraints of the Unix lab environment affecting debugging capabilities.

Who May Find This Useful

Individuals working on matrix operations in programming, particularly in C or similar languages, as well as those facing debugging challenges in Unix environments.

brad sue
Messages
270
Reaction score
0
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[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
 
Technology news on Phys.org
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?
 
berkeman said:
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.
 
-Job- said:
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:
 
brad sue said:
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[j];}
if (sum<1)
count=count+1;}
 

Similar threads

  • · Replies 75 ·
3
Replies
75
Views
7K
Replies
2
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 7 ·
Replies
7
Views
3K
Replies
9
Views
2K
  • · Replies 15 ·
Replies
15
Views
5K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 14 ·
Replies
14
Views
4K
  • · Replies 6 ·
Replies
6
Views
5K
  • · Replies 6 ·
Replies
6
Views
6K