Why is this simple output so difficult to code in C

  • Thread starter Thread starter camel-man
  • Start date Start date
  • Tags Tags
    Code Output
Click For Summary

Discussion Overview

The discussion revolves around a coding challenge in C, specifically focused on generating a specific output pattern. Participants explore the difficulties faced by the original poster (OP) in implementing the solution, with an emphasis on programming logic and structure.

Discussion Character

  • Homework-related
  • Technical explanation
  • Debate/contested

Main Points Raised

  • The OP expresses confusion about the simplicity of the output task and questions whether it is as easy as it appears.
  • Some participants emphasize the forum's purpose of guiding learners rather than providing complete solutions, suggesting that the OP should demonstrate their understanding first.
  • A participant suggests using pseudo-code to outline the logic needed to achieve the desired output, mentioning the need for loops to print the correct number of ones and twos.
  • There is a light-hearted debate about the number of "printf" statements required to achieve the output, with varying opinions on coding style and preferences.
  • Participants note that the discussion has diverged from the OP's original request, leading to the creation of a new thread for related discussions.

Areas of Agreement / Disagreement

Participants generally agree on the importance of helping the OP learn rather than providing direct answers. However, there is no consensus on the best approach to coding the solution or the specifics of the OP's problem.

Contextual Notes

Some participants mention the need for the OP to clarify their specific difficulties in order to receive more targeted assistance. The discussion also reflects varying levels of experience among participants, which may influence their perspectives on the coding challenge.

camel-man
Messages
76
Reaction score
0
1
1 2 1
1 2 1 2 1
1 2 1 2 1 2 1
1 2 1 2 1 2 1 2 1

I am stumped on how to do this, is it really as easy as it looks?
 
Technology news on Phys.org
Mod note: Deleted the portion that shows the answer to the problem in post #1.[/color]
Trueo, I see you are fairly new to the forum so perhaps you don't realize it, but the POINT of this forum is not to spoon-feed full answers to problems but to help people learn how to get their own answers by figuring out where they are having difficulty and giving them some help to get them over the next hump.

That is, we are not here to show how knowledgeable we are, we are here to help others get more knowledgeable.
 
Last edited by a moderator:
I just think people visiting PF are mostly students who are different from (advanced) employees; and I am not showing off with what I know, it is just a mini program, which doesn't build me into any person. :-)
 
trueo said:
I just think people visiting PF are mostly students who are different from (advanced) employees; and I am not showing off with what I know, it is just a mini program, which doesn't build me into any person. :-)

You are still missing the point.
 
trueo said:
I just think people visiting PF are mostly students who are different from (advanced) employees; and I am not showing off with what I know, it is just a mini program, which doesn't build me into any person. :-)

Physics Forums rules do not permit providing complete answers, especially when the original poster has not shown any work.
 
It's too long since I last programmed in C, so you'll have to make do with some pseudo-code. I guess you don't just want to output your example, but any kind of figure like this:

1
1 2 1
1 2 1 2 1
. . .
n ones and (n-1) twos alternating

The first thing I see here is that you want n rows, so you need some kind of loop:

for i = 1 to n do {
. . .
}

Those three dots must produce line number i, which is made up of i ones and (i-1) twos. Forget the twos for the moment, and you still need to print i ones -- with another loop:

for j = 1 to i do {
print "1"
}

Now if you can work out how to get those two loops (one for printing n lines, the other for printing i ones) to work together, all you need to add is the twos in between the ones.
 
Five "printf"s anyone?

OP probably should have been a bit more specific about exactly what was the problem if s/he wants a more specific answer.
 
uart said:
Five "printf"s anyone?
Or one :bugeye:.
 
Timo said:
Or one :bugeye:.
Yep. Or two or three, depending on how much you like or dislike long lines of source code. Take your pick. :smile:

It a funny question this one. How do you get these five lines of output, no other information or parameters given. :smile:
 
  • #10
Many posts, which took this thread far beyond its original intent as a simple homework-help request, have been moved into a new thread here:

https://www.physicsforums.com/showthread.php?t=655808

Please continue that discussion in the new thread. I apologize if I lost any posts in the process of transplanting them.
 

Similar threads

  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 1 ·
Replies
1
Views
2K
Replies
4
Views
2K
  • · Replies 34 ·
2
Replies
34
Views
6K
  • · Replies 9 ·
Replies
9
Views
2K
Replies
12
Views
3K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K