Forum   Search   Register   Log in SUPERJER FORA
 

C Puzzle!

Pages: [1]
Programming Help
superjer
superjer

2005 Mar 20 • 3742
This code is intended to print 20 minus signs, but it does not work:

#include <stdio.h>
main()
{
  int i = 0, n = 20;
  do
  {
    printf("-");
    i--;
  } while ( i < n );
}


There are at least 4 ways to fix it by changing exactly one character. Find!
    (Edited 2009 Jul 5 at 13:14)     2009 Jul 1 at 16:30
Down Rodeo
Cap'n Moth of the Firehouse

Find the Hole II Participation Medal
2007 Oct 19 • 5258
57,583 ₧
Change the i-- to n--? I don't know why that's a question, it works. But it should return an int :p

Not so sure what the others are; I shall have a little more think-time.
Everyone stares when you walk in the room, they stare when you go....
    2009 Jul 1 at 17:09
superjer
superjer

2005 Mar 20 • 3742
*** You have found 1 of the 4 solutions. ***

This is just a puzzle, don't worry about compiler warnings, etc. You don't have to return an int to get it to compile, anyway.
    2009 Jul 1 at 17:18
Down Rodeo
Cap'n Moth of the Firehouse

Find the Hole II Participation Medal
2007 Oct 19 • 5258
57,583 ₧
Ya, it compiled warning-free, which surprised me. I expected it to complain about my lack of a newline but nope, nothing.
Everyone stares when you walk in the room, they stare when you go....
    2009 Jul 1 at 17:25
Killer-Duck
Homicidal Anatidae

2008 Mar 5 • 1169
633 ₧

...
} while ( -i < n );


Maybe?
QUACK! QUACK!
    2009 Jul 2 at 13:18
Down Rodeo
Cap'n Moth of the Firehouse

Find the Hole II Participation Medal
2007 Oct 19 • 5258
57,583 ₧
I was going to ask if changing whitespace was allowed but that looks like a solution, kd.
Everyone stares when you walk in the room, they stare when you go....
    2009 Jul 3 at 14:15
superjer
superjer

2005 Mar 20 • 3742
*** You have found 2 of the 4 solutions. ***

Good job killer.

Yes, you can change a white-space character. But only ONE!
    2009 Jul 3 at 17:29
the_cloud_system
polly pushy pants

2008 Aug 1 • 2787
-6 ₧
ok im just gona ask
what
how
txt doc?
i dont know
can you explane
moo moo moo, moo.
    2009 Jul 3 at 18:13
Down Rodeo
Cap'n Moth of the Firehouse

Find the Hole II Participation Medal
2007 Oct 19 • 5258
57,583 ₧
It helps if you understand the basics of imperative programming. You don't even really need a compiler, thinking through it ought to work.

Uhm, changing the assignment n =-20; might work?
Everyone stares when you walk in the room, they stare when you go....
    2009 Jul 5 at 04:00
superjer
superjer

2005 Mar 20 • 3742
Down Rodeo said:
Uhm, changing the assignment n =-20; might work?


that will only print one minus sign because i is never less than n.
    2009 Jul 5 at 12:50
Down Rodeo
Cap'n Moth of the Firehouse

Find the Hole II Participation Medal
2007 Oct 19 • 5258
57,583 ₧
This is true. I didn't check it, I was guessing
Everyone stares when you walk in the room, they stare when you go....
    2009 Jul 6 at 09:44
thegreat
2009 Jul 9 • 1
WOW the most funny and newbie c puzzle ever...the increment shuld be
i++;

or make

.
.
.
int i=20,n=0;
do{
.
.
}while(i>n);
    (Edited 2009 Jul 9 at 08:19)     2009 Jul 9 at 08:18
Down Rodeo
Cap'n Moth of the Firehouse

Find the Hole II Participation Medal
2007 Oct 19 • 5258
57,583 ₧
But you see, thenotsogreat, neither of those involves changing exactly one character, which means you haven't solved the puzzle, friend.
Everyone stares when you walk in the room, they stare when you go....
    2009 Jul 9 at 09:10
Mate de Vita
Kelli

2008 Oct 4 • 2397
159 ₧
code
} while ( i + n );

I don't remember how exactly the while check works (is 0 true or false?), but would this work?
Anyway just bumping this truck.
...and that's the bottom line because Mate de Vita said so.

Who controls the past, controls the future. Who controls the present, controls the past.
    (Edited 2010 Jan 16 at 07:49)     2010 Jan 16 at 07:48
Down Rodeo
Cap'n Moth of the Firehouse

Find the Hole II Participation Medal
2007 Oct 19 • 5258
57,583 ₧
Ah, clever. Well done :) zero evaluates to false, all other values are true, I think.
Everyone stares when you walk in the room, they stare when you go....
    2010 Jan 16 at 09:28
superjer
superjer

2005 Mar 20 • 3742
It took a while but you got it. GG Mate Davate.
    2010 Jan 22 at 18:28

Pages: [1]
Forum and design copyright © 2008-2010 SuperJer.com