Matrix operations in C language

Click For Summary

Discussion Overview

The discussion revolves around programming matrix operations in the C language, specifically focusing on how to print specific numbers from a 4x4 matrix based on their row indices. The scope includes coding techniques and logic implementation for beginners.

Discussion Character

  • Homework-related
  • Technical explanation
  • Debate/contested

Main Points Raised

  • A participant presents a 4x4 matrix and requests assistance in writing a program to print specific numbers from each row corresponding to the row number.
  • One participant suggests using a nested loop to compare each digit of a row with the row number, indicating that this method aligns with the concept of searching.
  • Another participant proposes using a single loop to achieve the same output, suggesting it may be a simpler approach.
  • There is a discussion about the merits of each approach, with one participant arguing that the nested loop method better fits the theme of a searching program.
  • Another participant expresses interest in adapting the program to guess subsequent numbers, indicating a desire to explore beyond the initial task.

Areas of Agreement / Disagreement

Participants express differing opinions on the best approach to solve the problem, with some favoring a nested loop and others advocating for a single loop. The discussion remains unresolved regarding which method is superior.

Contextual Notes

Participants do not provide specific coding examples due to forum rules, and there is an emphasis on the conceptual understanding of the problem rather than a definitive solution.

phillosopher
Messages
4
Reaction score
0
i have a matrix 4x4 like this

1 5 7 3
2 6 8 0
1 4 3 2
0 4 0 5

my teacher asks me to print out 1 2 3 4
each of the digits is from the 1st 2nd 3rd 4th rows
it looks very simple, but because i just learned c for two months, i don't know how to code a program, true.

could you help me ?:shy:
thank you
 
Technology news on Phys.org
Hello phillosopher
The answer is quite simple.
I am not jotting down the actual code (it is against PF rules), but I will give you a hint.
Did you notice that the number that you have to print in each row is equal to the row-number. So just write a comparison-performing code, which compares each digit of a row with the row number. If the digit matches with the row-number, print the digit.
You will need a nested loop (a loop inside a loop) for this. Both the external and internal loops will need four iterations.

regards
Mr V
 
Mr Virtual said:
Hello phillosopher
The answer is quite simple.
I am not jotting down the actual code (it is against PF rules), but I will give you a hint.
Did you notice that the number that you have to print in each row is equal to the row-number. So just write a comparison-performing code, which compares each digit of a row with the row number. If the digit matches with the row-number, print the digit.
You will need a nested loop (a loop inside a loop) for this. Both the external and internal loops will need four iterations.

regards
Mr V
:biggrin:thank you,
I forget that life-saving spot.
No, I will use only one loop to output the number of rows. That'll be nicer, isn't it ?:-p
 
No, I will use only one loop to output the number of rows. That'll be nicer, isn't it ?
Yeah, you can easily do that. But if you want the program to look like a "searching" program (that's the topic of your thread), then the approach I suggested will be better.
 
Last edited:
Mr Virtual said:
Yeah, you can easily do that. But if you want the program to look like a "searching" program (that's the topic of your thread), then the approach I suggested will be better.
Yes, that approach is better for the searching program because I suppose I can make the program guess what number comes next especially when the numbers don't denote the row's numbers, thank you, :biggrin:
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 23 ·
Replies
23
Views
3K
Replies
1
Views
1K
  • · Replies 25 ·
Replies
25
Views
3K
  • · Replies 19 ·
Replies
19
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
Replies
6
Views
3K