473,394 Members | 1,701 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Stairs program

I'm trying to write a stairs program. It's supposed to print stairs.
This is what I got:
+---+
| |
+---+---+
| | |
+---+---+---+
| | | |
+---+---+---+---+
| | | | |
+---+---+---+---+---+
| | | | | |
+---+---+---+---+---+---+
| | | | | | |
+---+---+---+---+---+---+
Now I can't figure out how to get it to print the inverse to the left
so it looks like a pyramid.
The code:
#include <stdio.h>

void makeTread (int n_tread)
{
int i;

printf("+");
for (i = 0; i < n_tread; i++)
{
printf("---+");
}
printf("\n");
}

void makeRise (int n_rise)
{
int i;

for (i = 0; i < n_rise; i++)
{
printf("| ");
}
printf("\n");
}

void makeStairs (int N)
{
int k;

for (k=1; k <= N; k++)
{
makeTread (k);
makeRise (k + 1);
}
makeTread (N);
}

int
main(void)
{
makeStairs (6);

return (0);
}

Can somebody give me a hint?

Nov 3 '06 #1
4 5266
On Thu, 2006-11-02 at 20:57 -0800, bluepgt wrote:
I'm trying to write a stairs program. It's supposed to print stairs.
This is what I got:
+---+
| |
+---+---+
| | |
+---+---+---+
| | | |
+---+---+---+---+
| | | | |
+---+---+---+---+---+
| | | | | |
+---+---+---+---+---+---+
| | | | | | |
+---+---+---+---+---+---+
Now I can't figure out how to get it to print the inverse to the left
so it looks like a pyramid.
Who's your teacher? Tell him that he's doing a great job: this is the
most well-written "hobby program" I've seen in a long time. If you're
self-taught, then congratulations. (The only issue I see is that you
shouldn't use tabs on Usenet: they may not display correctly or at all,
and some newsservers filter them out.)
The code:
#include <stdio.h>

void makeTread (int n_tread)
{
int i;

printf("+");
for (i = 0; i < n_tread; i++)
{
printf("---+");
}
printf("\n");
}

void makeRise (int n_rise)
{
int i;

for (i = 0; i < n_rise; i++)
{
printf("| ");
}
printf("\n");
}

void makeStairs (int N)
{
int k;

for (k=1; k <= N; k++)
Note: It's best to start with 0 and go up to one less than N:
for(k = 0; k < N; k++)
This is a more common idiom.
{
makeTread (k);
makeRise (k + 1);
}
makeTread (N);
}

int
main(void)
{
makeStairs (6);

return (0);
The return statement doesn't need parentheses, just so you know.
}

Can somebody give me a hint?
In order to draw a pyramid properly, you'll need to know the base size,
in order to center the top correctly. From an algorithmic perspective,
this could be tricky. You'll need to pass a base_size value to your
makeTread() and makeRise() functions, and then add spacing
appropriately.

If you want to print both sides at the same time, and want your top
level to have one box instead of two (so that it isn't mirrored
boxwise, but instead half-boxwise), you'll have some more problems.
Take a pencil and paper, and write out equations for:
1) The number of boxes at each level.
2) The amount of spaces needed.
3) The most height you can get before exceeding 80 characters (which
is the maximum width of many terminals).

Finally, I recommend that you also post your question in
comp.programming; you'll probably get some more help there.

--
Andrew Poelstra <http://www.wpsoftware.net>
For email, use 'apoelstra' at the above site.
"You're only smart on the outside." -anon.

Nov 3 '06 #2
2006-11-03 <1162531994.6788.11.camel@abacus>,
Andrew Poelstra wrote:
(The only issue I see is that you shouldn't use tabs on Usenet: they
may not display correctly or at all, and some newsservers filter them
out.)
I've never heard of a newsserver doing that. Is that even allowed by the
nntp/usenet standards?
Nov 3 '06 #3
Jordan Abel wrote:
2006-11-03 <1162531994.6788.11.camel@abacus>,
Andrew Poelstra wrote:
>(The only issue I see is that you shouldn't use tabs on Usenet: they
may not display correctly or at all, and some newsservers filter them
out.)

I've never heard of a newsserver doing that. Is that even allowed by the
nntp/usenet standards?
Whether it is allowed and whether it is the server, the posting client,
or the receiving client, we have seen it happen here many times.
--
Flash Gordon
Nov 3 '06 #4
In article <sl*******************@rlaptop.random.yi.org>,
Jordan Abel <ra*******@gmail.comwrote:
>2006-11-03 <1162531994.6788.11.camel@abacus>,
Andrew Poelstra wrote:
>(The only issue I see is that you shouldn't use tabs on Usenet: they
may not display correctly or at all, and some newsservers filter them
out.)

I've never heard of a newsserver doing that. Is that even allowed by the
nntp/usenet standards?
nntp requires 7 bit ASCII (the 8th bit is explicitly zeroed.)
The message body definition falls through to the Usenet
message definition, which in turn for the body falls through to RFC822,
the email definition. And RFC822 indicates that message bodies
consist of streams CRLF delimited lines of any ascii character
(0-127) [except for CRLF].

Which is to say, you are correct that news servers -should- be passing
tabs through unchanged. But posting clients and reading clients
mess tabs up more often than not.
--
All is vanity. -- Ecclesiastes
Nov 3 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

22
by: edgrsprj | last post by:
PROPOSED EARTHQUAKE FORECASTING COMPUTER PROGRAM DEVELOPMENT EFFORT Posted July 11, 2005 My main earthquake forecasting Web page is: http://www.freewebz.com/eq-forecasting/Data.html ...
0
by: Tom Lee | last post by:
Hi, I'm new to .NET 2003 compiler. When I tried to compile my program using DEBUG mode, I got the following errors in the C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7 \include\xdebug...
11
by: christopher diggins | last post by:
I am wondering if any can point me to any open-source library with program objects for C++ like there is in Java? I would like to be able to write things like MyProgram1 >> MyProgram2 >>...
1
by: Eric Whittaker | last post by:
hi all, im trying to write my first c++ program. a success, but i can't get the window to stay open after user enters input. it just automatically closes. right now the end of my program looks...
9
by: Hemal | last post by:
Hi All, I need to know the memory required by a c program. Is there any tool/utility which can give me the memory usage in terms of DATA segment, TEXT segment, BSS segment etc. I am working...
7
by: ibtc209 | last post by:
I just started programming in C, and I need some help with this problem. Your program will read the information about one MiniPoker hand, namely the rank and suit of the hand’s first card, and...
2
Banfa
by: Banfa | last post by:
Posted by Banfa The previous tutorial discussed what programming is, what we are trying to achieve, the answer being a list of instructions constituting a valid program. Now we will discuss how...
0
amitpatel66
by: amitpatel66 | last post by:
There is always a requirement that in Oracle Applications, the Concurrent Program need to be execute programatically based on certain conditions/validations: Concurrent programs can be executed...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.