472,967 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 472,967 software developers and data experts.

formated output excer (help)

I have got a book called "Practical C Programming", ISBN:1-56592-306-5
Publisher: O'Reilly.In that book I am doing some programming exercises.
Below is a one which I have got stuck.

Exercise 4-2: Write a program to print a block E using asterisks (*), where
the E has a height of seven characters and a width of five characters.

The solution which I have tried is

#include<stdio.h>
int main(void)
{
unsigned short i;
for(i=0;i<8;i++)
{
printf("*");
if((i == 1) && (i < 5))
{
printf("*\n");
}
if((i == 5) && (i < 9))
{
printf("*");
}
if(i < 7)
{
printf("*\n");
}
}
return 0;
}
not correct. Can any one give me the logic(*dont give out the solution

or the coding*). Thanks.
Feb 7 '06 #1
3 1482
sathyashrayan wrote:
I have got a book called "Practical C Programming", ISBN:1-56592-306-5
Publisher: O'Reilly.In that book I am doing some programming exercises.
Below is a one which I have got stuck.

Exercise 4-2: Write a program to print a block E using asterisks (*), where
the E has a height of seven characters and a width of five characters.
Do you mean

***** <== line 1 (or 0)
* <== line 2 (or 1)
* <== 3
***** <== 4
* <== 5
* <== 6
***** <== 7
The solution which I have tried is

#include<stdio.h>
int main(void)
{
unsigned short i;
for(i=0;i<8;i++)
/*
* this loop will execute 8 times:
* first with i == 0, then 1, then 2, ...
* and finally 7. Count them: 01234567
* */
{
printf("*");
/*
* start the loop by printing a '*'. Sounds good
* */
if((i == 1) && (i < 5))
/*
* if we're on the second row (remember you started i with 0?)
* and the second row is before the sixth ...
* */
{
printf("*\n");
/*
* ... print another '*' and a newline.
* This doesn't sound so good.
* */
}
if((i == 5) && (i < 9))
/* more if confusion */
{
printf("*");
}
if(i < 7)
{
printf("*\n");
}
}
return 0;
}
not correct. Can any one give me the logic(*dont give out the solution

or the coding*).


You're printing too many '\n'. You want one for each time through the
loop.
for (i = 0; i < 7; ++i)
{
printf("*");
/* deal with more '*'s for i==0, i==3 and i==6 */
/* WOW I just noticed something interesting (*) */
printf("\n");
}


(*) the long lines of the E can be recognized with one instruction.

--
If you're posting through Google read <http://cfaj.freeshell.org/google>
Feb 7 '06 #2
Pedro Graca wrote:
sathyashrayan wrote:
I have got a book called "Practical C Programming", ISBN:1-56592-306-5
Publisher: O'Reilly.In that book I am doing some programming exercises.
Below is a one which I have got stuck.

Exercise 4-2: Write a program to print a block E using asterisks (*), where
the E has a height of seven characters and a width of five characters.


Do you mean

***** <== line 1 (or 0)
* <== line 2 (or 1)
* <== 3
***** <== 4
* <== 5
* <== 6
***** <== 7


puts("*****\n"
"*\n
"*\n"
"*****\n"
"*\n
"*\n
"*****");

seems to meet the requirements :-)

--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
More details at: <http://cfaj.freeshell.org/google/>
Also see <http://www.safalra.com/special/googlegroupsreply/>
Feb 7 '06 #3
Groovy hepcat CBFalconer was jivin' on Tue, 07 Feb 2006 00:45:38 -0500
in comp.lang.c.
Re: formated output excer (help)'s a cool scene! Dig it!
Pedro Graca wrote:
sathyashrayan wrote:
I have got a book called "Practical C Programming", ISBN:1-56592-306-5
Publisher: O'Reilly.In that book I am doing some programming exercises.
Below is a one which I have got stuck.

Exercise 4-2: Write a program to print a block E using asterisks (*), where
the E has a height of seven characters and a width of five characters.
Do you mean

***** <== line 1 (or 0)
* <== line 2 (or 1)
* <== 3
***** <== 4
* <== 5
* <== 6
***** <== 7


puts("*****\n"
"*\n

^
Missing "
"*\n"
"*****\n"
"*\n ^
Missing "
"*\n ^
Missing "
"*****");

seems to meet the requirements :-)


In a strange, mysterious other dimension in which quotes are not
required at the end of strings, maybe. :)

--

Dig the even newer still, yet more improved, sig!

http://alphalink.com.au/~phaywood/
"Ain't I'm a dog?" - Ronny Self, Ain't I'm a Dog, written by G. Sherry & W. Walker.
I know it's not "technically correct" English; but since when was rock & roll "technically correct"?
Feb 9 '06 #4

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

Similar topics

5
by: Norbert Thek | last post by:
Hi I'm using Python 24 on Windows > (2k) Is there an easy way to convince optparse to accept newline in the helpstring? and more importand also in the 'desc' string. I tried everything (from...
3
by: Emil Dotchevski | last post by:
I have a table that is at 100% width, which contains a <TD> that is 80% of that. In the <TD> I want to put pre-formatted text (the output from a C++ compiler, to be more precise) and I'd like the...
3
by: sb Luis | last post by:
I Use the following code to read from MS Word, but I couldent read Formated Text (RTF). How Can I read formated text from MS Word Doc without using clipboard. thanks. Word.ApplicationClass...
5
by: Elhanan | last post by:
hi.. i don't exactly how to calls this , but is there a property for xalan, to output xml with crarriage return? i'm trying out xslt and the output can't be read with a normal editor, i know...
0
southoz
by: southoz | last post by:
Good ay all , I'm fairly new to access(a little over 5 weeks now). Since I'v started I have picked up a lot of useful information from forums such as this and in doing so will share that information...
1
by: sambavikedar | last post by:
I have a query like this :- spool c:\daily.xls select message_id||chr(9)||account_name from table where <> message_id number account_name ...
1
by: =?Utf-8?B?R3JlZyBH?= | last post by:
A aspx page Label.Text contains formated currency ("0:C"). To process this data with the submit button click it needs to be converted to a decimal. For example: string strCur = "$111.11"; //...
2
by: Nikola Skoric | last post by:
I have been trying to find appropriate way to do get local time in "yyyy-mm-dd hh:mm:ss" format, but the best I got is this: datetime.datetime.fromtimestamp(time.mktime(time.localtime())) It seems...
1
by: vova777 | last post by:
On Jul 7, 6:21pm, r...@zedat.fu-berlin.de (Stefan Ram) wrote: That is as simple as - std::ostream out(std::cout.rdbuf()); out << "state free formatted output"; Kind regards, Vladimir
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
2
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.