473,385 Members | 1,647 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,385 software developers and data experts.

For loops help

Dear everyone,

Can someone please help me on my HW. I'm trying to write a program
that will display the following:

*
***
*****
*******
*********
*********
*******
*****
***
*

I'm having a hard time writing a code for this one. I tried several
times, but I can't get it to work properly. I live in Japan and I take
an online C++ course. The instructor lives in the US so whenever I am
awake, he's asleep. Therefore, I cannot contact him directly when I
need help. I have to get this program up and running ASAP. I tried
searching everywhere for help, but there's none except for this group.
My textbook isn't much of a help either. I WILL GREATLY APPRECIATE THE
HELP I WILL GET!

May 11 '06 #1
20 2233

pa***********@gmail.com wrote:
Dear everyone,

Can someone please help me on my HW. I'm trying to write a program
that will display the following:

*
***
*****
*******
*********
*********
*******
*****
***
*

I'm having a hard time writing a code for this one. I tried several
times, but I can't get it to work properly. I live in Japan and I take
an online C++ course. The instructor lives in the US so whenever I am
awake, he's asleep. Therefore, I cannot contact him directly when I
need help. I have to get this program up and running ASAP. I tried
searching everywhere for help, but there's none except for this group.
My textbook isn't much of a help either. I WILL GREATLY APPRECIATE THE
HELP I WILL GET!


Post some of the attempts you have made. Nobody will just give you the
solution. Also, read the link below, especially where it talks about
(or links to) how a homework question should be asked:

http://www.clc-wiki.net/wiki/Introdu...to_comp.lang.c

I can offer one solution, though I doubt that's what you're looking
for:

#include <stdio.h>

int main(void)
{
int i;

for (i=0; i<1; i++)
{
printf(" *\n");
printf(" ***\n");
printf(" *****\n");
printf(" *******\n");
printf("*********\n");
printf("*********\n");
printf(" *******\n");
printf(" *****\n");
printf(" ***\n");
printf(" *\n");
}

return 0;
}

May 11 '06 #2
pa***********@gmail.com wrote:
Can someone please help me on my HW. I'm trying to write a program
that will display the following:
(snip asterisks)
I'm having a hard time writing a code for this one. I tried several
times, but I can't get it to work properly.
Post your best attempt. We'll fix your code, but we won't write it
for you.
I live in Japan and I take
an online C++ course.


And post to the correct newsgroup. comp.lang.c++ is that way ---->

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
May 11 '06 #3
pa***********@gmail.com wrote:
Can someone please help me on my HW. I'm trying to write a program
that will display the following:

*
***
*****
*******
*********
*********
*******
*****
***
*
#include <stdio.h>

int main(void)
{
puts(" *");
puts(" ***");
puts(" *****");
puts(" *******");
puts("*********");
puts("*********");
puts(" *******");
puts(" *****");
puts(" ***");
puts(" *");
puts("");
puts("Copyright 2006 Richard L. Bos - all rights reserved.");

return 0;
}
I'm having a hard time writing a code for this one. I tried several
times, but I can't get it to work properly. I live in Japan and I take
an online C++ course.
Then a. you want to replace <stdio.h> with something like <cstdio.h++>;
b. you want something like stdout << instead of puts(; and c. you need
to ask in comp.lang.c++, not comp.lang.c.
The instructor lives in the US so whenever I am awake, he's asleep.
Therefore, I cannot contact him directly when I need help.
They don't have e-mail in the US? Gosh. I knew that country was a bit
primitive in some aspects, but that's truly backwards.
I have to get this program up and running ASAP.


I really, really doubt that.

FWIW: DYODH. HTH; HAND.

Richard
May 11 '06 #4
pa***********@gmail.com wrote:
*
***
*****
*******
*********
*********
*******
*****
***
*


/* BEGIN new.c */

#include <stdio.h>
#include <string.h>

#define FIVE 5

void function(char *array, int max, int limit);
char *str_rev(char *s);

int main(void)
{
char array[FIVE] = "";
int counter;

counter = FIVE;
while (counter-- != 0) {
function(array, FIVE - 1, counter);
}
for (counter = 0; counter != FIVE; ++counter) {
function(array, FIVE - 1, counter);
}
return 0;
}

void function(char *array, int max, int limit)
{
int count;

for (count = 0; count != limit; ++count) {
array[count] = ' ';
}
while (count != max) {
array[count] = '*';
++count;
}
printf(array);
putchar('*');
str_rev(array);
puts(array);
}

char *str_rev(char *s)
{
char *t, swap;
char *const p = s;

if (s[0] != '\0' && s[1] != '\0') {
t = s + 1 + strlen(s + 2);
do {
swap = *t;
*t-- = *s;
*s++ = swap;
} while (t > s);
}
return p;
}

/* END new.c */

--
pete
May 11 '06 #5
<pa***********@gmail.com> wrote:
Can someone please help me on my HW. I'm trying to write a program
that will display the following:

*
***
*****
*******
*********
*********
*******
*****
***
*

I'm having a hard time writing a code for this one. I tried several
times, but I can't get it to work properly. I live in Japan and I take
an online C++ course. The instructor lives in the US so whenever I am
awake, he's asleep. Therefore, I cannot contact him directly when I
need help. I have to get this program up and running ASAP. I tried
searching everywhere for help, but there's none except for this group.
My textbook isn't much of a help either. I WILL GREATLY APPRECIATE THE
HELP I WILL GET!


Resolve to do it in two parts, the asterisks are growing or the asterisks
are shrinking.

For the growing asterisks:
Write two functions, one to print n spaces and another to print n asterisks.
Call these functions with the appropriate parameters, and have the main loop
provide the end of line. That is, one iteration of the for loop prints one
*line*.

Make a table like this:

line nbr nbr asterisks
1 1
2 3
3 5
4 6

Note the sequence and provide appropriate code in the for loop to provide
the appropriate value to the asterisk printing function.

Note well how the liberal use of functions empties the mind of extraneous
non-interesting (at the moment) things.

Now do the shrinking asterisks bit.

Done.
-----
I *finally* figured out what HW is. Homework!
May 11 '06 #6
pa***********@gmail.com said:
Dear everyone,

Can someone please help me on my HW. I'm trying to write a program
that will display the following:

*
***
*****
*******
*********
*********
*******
*****
***
*

I'm having a hard time writing a code for this one. I tried several
times, but I can't get it to work properly. I live in Japan and I take
an online C++ course. The instructor lives in the US so whenever I am
awake, he's asleep. Therefore, I cannot contact him directly when I
need help. I have to get this program up and running ASAP. I tried
searching everywhere for help, but there's none except for this group.
My textbook isn't much of a help either. I WILL GREATLY APPRECIATE THE
HELP I WILL GET!


My pleasure.

#define M 002354l
#define A 000644l
#define G 000132l
#define I 000322l
#define C 000374l

#define a ;
#define b for
#define c ++
#define d %
#define e int
#define f ,
#define g -
#define h 011
#define i =
#define j {
#define k )
#define l '\n'
#define m main
#define n <
#define o }
#define p >
#define q &&
#define r (
#define s ||
#define t ?
#define u putchar
#define v void
#define w '*'
#define x :
#define y ' '
#define _ /
#define C_O_O_L return

e u r e k a

e
m r
v k j
j j j j
j j j j j
j j j j j j
j j j j j j j
j e z a b r z i
M _ A _ G _ I _ C
a z n G a u r z d h
+ z _ h p M _ A q z d
h + z _ h n M _ G q z _
h n z d h + M _ I q z _ h
p z d h g M _ C t w x y k f
z d h g h + 1 s u r l k f z c
k a u r l k a j j j j j j j j j
j j C_O_O_L M _ A _ G _ I _ C a o
o o o o o o o o o o o o o o o o o o
o o o o
o o o o
o o o o
o o o o
--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
May 11 '06 #7

Richard Heathfield wrote:
pa***********@gmail.com said:
Dear everyone,

Can someone please help me on my HW. I'm trying to write a program
that will display the following:

*
***
*****
*******
*********
*********
*******
*****
***
*

I'm having a hard time writing a code for this one. I tried several
times, but I can't get it to work properly. I live in Japan and I take
an online C++ course. The instructor lives in the US so whenever I am
awake, he's asleep. Therefore, I cannot contact him directly when I
need help. I have to get this program up and running ASAP. I tried
searching everywhere for help, but there's none except for this group.
My textbook isn't much of a help either. I WILL GREATLY APPRECIATE THE
HELP I WILL GET!


My pleasure.

#define M 002354l
#define A 000644l
#define G 000132l
#define I 000322l
#define C 000374l

#define a ;
#define b for
#define c ++
#define d %
#define e int
#define f ,
#define g -
#define h 011
#define i =
#define j {
#define k )
#define l '\n'
#define m main
#define n <
#define o }
#define p >
#define q &&
#define r (
#define s ||
#define t ?
#define u putchar
#define v void
#define w '*'
#define x :
#define y ' '
#define _ /
#define C_O_O_L return

e u r e k a

e
m r
v k j
j j j j
j j j j j
j j j j j j
j j j j j j j
j e z a b r z i
M _ A _ G _ I _ C
a z n G a u r z d h
+ z _ h p M _ A q z d
h + z _ h n M _ G q z _
h n z d h + M _ I q z _ h
p z d h g M _ C t w x y k f
z d h g h + 1 s u r l k f z c
k a u r l k a j j j j j j j j j
j j C_O_O_L M _ A _ G _ I _ C a o
o o o o o o o o o o o o o o o o o o
o o o o
o o o o
o o o o
o o o o


Thank you! You've definitely made my day! LoL

May 11 '06 #8
On Thu, 11 May 2006 14:00:50 +0000,
Richard Heathfield <in*****@invalid.invalid> wrote
in Msg. <Iv******************************@bt.com>

#define M 002354l
#define A 000644l
#define G 000132l
#define I 000322l
#define C 000374l
[...]
h n z d h + M _ I q z _ h
p z d h g M _ C t w x y k f
z d h g h + 1 s u r l k f z c
k a u r l k a j j j j j j j j j
j j C_O_O_L M _ A _ G _ I _ C a o
o o o o o o o o o o o o o o o o o o
o o o o
o o o o
o o o o
o o o o


OK, let's un-obfuscate this a little bit:

------
int putchar(int);

int main(void)
{
int z;

for (z =
002354l / 000644l / 000132l / 000322l / 000374l; z < 000132l;
putchar(z % 011 + z / 011 > 002354l / 000644l
&& z % 011 + z / 011 < 002354l / 000132l
&& z / 011 < z % 011 + 002354l / 000322l
&& z / 011 > z % 011 - 002354l / 000374l ? '*' : ' '),
z % 011 - 011 + 1 || putchar('\n'), z++);
putchar('\n');
return 002354l / 000644l / 000132l / 000322l / 000374l;
}
------

Ho do you come up with stuff like this? I don't get it. My mind doesn't
work that way.

Puzzled,
robert

May 11 '06 #9
Robert Latest said:
for (z =
002354l / 000644l / 000132l / 000322l / 000374l; z < 000132l;
putchar(z % 011 + z / 011 > 002354l / 000644l
&& z % 011 + z / 011 < 002354l / 000132l
&& z / 011 < z % 011 + 002354l / 000322l
&& z / 011 > z % 011 - 002354l / 000374l ? '*' : ' '),
z % 011 - 011 + 1 || putchar('\n'), z++);
putchar('\n');
return 002354l / 000644l / 000132l / 000322l / 000374l;
}
------

Ho do you come up with stuff like this? I don't get it. My mind doesn't
work that way.


Well, I see no point using two loops when one will do, that's all.

I also don't think a program is sufficiently obfuscated if its workings are
immediately clear to the reader after running the source through cpp and
indent!

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
May 11 '06 #10
lovely. This surely redefines creative programming.
May 14 '06 #11
Toni <de*******@gmail.com> writes:
lovely. This surely redefines creative programming.


What does?

Read <http://cfaj.freeshell.org/google/>.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
May 14 '06 #12
just a test. i just can speak a little englise.

everybody's answer is so interesting that i can not help reply

May 14 '06 #13
zw************@gmail.com wrote:

just a test. i just can speak a little englise.

everybody's answer is so interesting that i can not help reply


Then read and heed the following sig.

--
"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/>
May 14 '06 #14
On 2006-05-14, CBFalconer <cb********@yahoo.com> wrote:
zw************@gmail.com wrote:

just a test. i just can speak a little englise.

everybody's answer is so interesting that i can not help reply


Then read and heed the following sig.


Your sig didn't show that time, it seems.

Here it is, basically: Click on 'More Options' and 'Add Reply' to reply
using the Google Groups interface. Don't use the broken 'Reply' button.
May 14 '06 #15
Andrew Poelstra opined:
On 2006-05-14, CBFalconer <cb********@yahoo.com> wrote:
zw************@gmail.com wrote:

just a test. i just can speak a little englise.

everybody's answer is so interesting that i can not help reply


Then read and heed the following sig.


Your sig didn't show that time, it seems.

Here it is, basically: Click on 'More Options' and 'Add Reply' to
reply using the Google Groups interface. Don't use the broken 'Reply'
button.


Looked quite alright for me, strangely enough (KNode on SUSE). Usenet
*is* a strange place, after all.

--
Fascinating is a word I use for the unexpected.
-- Spock, "The Squire of Gothos", stardate 2124.5

<http://clc-wiki.net/wiki/Introduction_to_comp.lang.c>

May 14 '06 #16
Andrew Poelstra wrote:
On 2006-05-14, CBFalconer <cb********@yahoo.com> wrote:
zw************@gmail.com wrote:

just a test. i just can speak a little englise.

everybody's answer is so interesting that i can not help reply


Then read and heed the following sig.


Your sig didn't show that time, it seems.

Here it is, basically: Click on 'More Options' and 'Add Reply' to
reply using the Google Groups interface. Don't use the broken
'Reply' button.


It normally shows, and is in the usenet article. The only place it
should be suppressed is in a reply to my article. If your reader
doesn't show it on a normal read, something is wrong with your
reader.

--
"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/>

May 14 '06 #17
On 2006-05-14, CBFalconer <cb********@yahoo.com> wrote:
Andrew Poelstra wrote:
On 2006-05-14, CBFalconer <cb********@yahoo.com> wrote:
zw************@gmail.com wrote:

just a test. i just can speak a little englise.

everybody's answer is so interesting that i can not help reply

Then read and heed the following sig.


Your sig didn't show that time, it seems.

Here it is, basically: Click on 'More Options' and 'Add Reply' to
reply using the Google Groups interface. Don't use the broken
'Reply' button.


It normally shows, and is in the usenet article. The only place it
should be suppressed is in a reply to my article. If your reader
doesn't show it on a normal read, something is wrong with your
reader.


True, but the interesting thing is that it /does/ show in every single
post you make, with the exception of the one that I replied to.
Perhaps my ISP's news server flaked out or something.
May 14 '06 #18
Andrew Poelstra <ap*******@localhost.localdomain> writes:
On 2006-05-14, CBFalconer <cb********@yahoo.com> wrote:
Andrew Poelstra wrote:
On 2006-05-14, CBFalconer <cb********@yahoo.com> wrote:
zw************@gmail.com wrote:
>
> just a test. i just can speak a little englise.
>
> everybody's answer is so interesting that i can not help reply

Then read and heed the following sig.

Your sig didn't show that time, it seems.

Here it is, basically: Click on 'More Options' and 'Add Reply' to
reply using the Google Groups interface. Don't use the broken
'Reply' button.


It normally shows, and is in the usenet article. The only place it
should be suppressed is in a reply to my article. If your reader
doesn't show it on a normal read, something is wrong with your
reader.


True, but the interesting thing is that it /does/ show in every single
post you make, with the exception of the one that I replied to.
Perhaps my ISP's news server flaked out or something.


That is odd. The sig definitely showed up when I read the article.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
May 14 '06 #19
On 2006-05-14, Andrew Poelstra wrote:
On 2006-05-14, CBFalconer <cb********@yahoo.com> wrote:
zw************@gmail.com wrote:

just a test. i just can speak a little englise.

everybody's answer is so interesting that i can not help reply


Then read and heed the following sig.


Your sig didn't show that time, it seems.


In slrn, toggle showing the sig with \.

--
Chris F.A. Johnson, author <http://cfaj.freeshell.org>
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence
May 15 '06 #20
On 2006-05-15, Chris F.A. Johnson <cf********@gmail.com> wrote:
On 2006-05-14, Andrew Poelstra wrote:
On 2006-05-14, CBFalconer <cb********@yahoo.com> wrote:
zw************@gmail.com wrote:

just a test. i just can speak a little englise.

everybody's answer is so interesting that i can not help reply

Then read and heed the following sig.


Your sig didn't show that time, it seems.


In slrn, toggle showing the sig with \.


Thanks, Chris. I'm going to take a trek through my help files now...
May 15 '06 #21

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

Similar topics

4
by: dw | last post by:
Hello all. We're doing a site with teams and their members. We've got a page where we need to display people according to who belongs to a which team. I've heard that nested loops are bad, but...
15
by: JustSomeGuy | last post by:
I have a need to make an applicaiton that uses a variable number of nested for loops. for now I'm using a fixed number: for (z=0; z < Z; ++z) for (y=0; y < Y; ++y) for (x=0; x < X; ++x)
4
by: Dr. David Kirkby | last post by:
I have a program that loops through and changes all the elements on an array n times, so my code looks like this: for (n=1; n < n_max; ++n) for(i=imax; i >= 0; --i) { for(j=0 ; j < jmax; ++j) {...
77
by: Peter Olcott | last post by:
http://www.tommti-systems.de/go.html?http://www.tommti-systems.de/main-Dateien/reviews/languages/benchmarks.html The above link shows that C# is 450% slower on something as simple as a nested loop....
7
by: paolo.arimado | last post by:
Dear everyone, Can someone please help me on my HW. I'm trying to write a program that will display the following: * *** ***** ******* *********
10
by: Putty | last post by:
In C and C++ and Java, the 'for' statement is a shortcut to make very concise loops. In python, 'for' iterates over elements in a sequence. Is there a way to do this in python that's more concise...
2
by: bitong | last post by:
I'm a little bit confuse with regard to our subject in C..We are now with the Loops..and I was just wondering if given a problem, can you use Do-while loops instead of a for loops or vise versa? are...
5
Reika
by: Reika | last post by:
Hello, I need help understanding some things in programming. I'm taking a high school level programming course, however my teacher is less than helpful in explaining or even understanding the...
4
by: danbuttercup | last post by:
Hi everyone I just recently learnt how to do while loops in my java class and I am completely lost. I have to make programs for the following questions but I have no idea were to start. ...
8
by: Nathan Sokalski | last post by:
I have several nested For loops, as follows: For a As Integer = 0 To 255 For b As Integer = 0 To 255 For c As Integer = 0 To 255 If <Boolean ExpressionThen <My CodeElse Exit For Next If Not...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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...

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.