Page 1 of 1
Posted: Sun Oct 03, 2004 5:28 pm
by fr0d
Hay guys, I have to take a stupid C course, and since I hate programming and computers in general, I am find some stuff hard. Like this questions.
I gotta write a program using only the following three output statements
(Each one appearing ONLY ONCE in your program):
printf("* "); printf(" "); printf("\n");
I am only allowed to use stuff like the if, and while stuff, and the output is supposed to be
* * * * * * * *
_ * * * * * * * *
* * * * * * * *
_ * * * * * * * *
* * * * * * * *
_ * * * * * * * *
* * * * * * * *
_ * * * * * * * *
(_ means a space, I cant get it to show)
If you help me I be best friend long time!
Here is the code I have so far, it doesn't work :(
#include <stdio.h>
int main()
{
? ? ? ?int counter1;
? ? ? ?int counter2;
? ? ? ?int counter3;
? ? ? ?counter1 = 0;
? ? ? ?counter2 = 0;
? ? ? ?counter3 = 0;
while ( counter1 != 4 ) {
? ? ? ?while ( counter2 != 8 ) {
? ? ? ?counter2 = counter2 + 1;
? ? ? ?counter3 = counter3 + 1;
? ? ? ?printf ( "* " );
? ? ? ? ? ? ? ?if ( counter3 == 8 ) {
? ? ? ? ? ? ? ? ? ? ? ?printf ( "\n" );
? ? ? ? ? ? ? ? ? ? ? ?printf ( " " );
? ? ? ? ? ? ? ?}
? ? ? ?}
counter1 = counter1 + 1;
counter3 = 0;
counter2 = 0;
}
return 0;
}
Posted: Sun Oct 03, 2004 9:30 pm
by JFK
Posted: Mon Oct 04, 2004 12:00 am
by Michael-Corleone
paging miguel paolo jagelo
Posted: Mon Oct 04, 2004 12:19 am
by sh3p
Posted: Mon Oct 04, 2004 12:32 am
by MikeJ
This should work dawg
#include <stdio.h>
int main()
{
int iLines = 0;
int iStars = 0;
while ( iLines != 8 )
{
while ( iStars != 8 )
{
if ( (iLines % 2) == 1 && iStars == 0 )
{
printf( " " );
}
printf( "*" );
iStars++;
}
iStars = 0;
printf( "\n" );
iLines++;
}
return 0;
}
iLines % 2 returns 1 if odd, else returns 0 if even.
Posted: Mon Oct 04, 2004 3:14 am
by Hamburglar
I have no idea what's going on in this thread.
MikeJ is the man.
Posted: Mon Oct 04, 2004 5:26 am
by fr0d
This should work dawg
#include <stdio.h>
int main()
{
?int iLines = 0;
?int iStars = 0;
?
?
?while ( iLines != 8 )
?{
? ?while ( iStars != 8 )
? ?{
? ? ?if ( (iLines % 2) == 1 && iStars == 0 )
? ? ?{
? ? ? ?printf( " " );
? ? ?}
? ? ?
? ? ?printf( "*" );
? ? ?iStars++;
? ?}
? ?iStars = 0; ?
? ?printf( "\n" );
? ?iLines++;
?}
?return 0;
}
iLines % 2 returns 1 if odd, else returns 0 if even.
I love you in the most manly way possible. Thanks a bunch, this has been racking my mind for days
Posted: Tue Oct 05, 2004 2:38 pm
by Stiffer
Posted: Wed Oct 06, 2004 3:49 am
by mr_lee
I have no idea what's going on in this thread.
MikeJ is the man.
my oath he is. that's mad! nice one mike :)
gj gj
what a helping community we are :)