| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | Re: [C] C Puzzles |
2. The "R" word makes it a lot easier:
#include
void doit(int what)
{
if (what > 100) return;
printf("%d, ", what);
doit(what+1);
printf("%d, ", what);
}
int main()
{
doit(1);
return 0;
}
LP>From: "Len Philpot"
LP>> 2. Write a C program without using any loop (if, for, while etc) to
LP>> print numbers from 1 to 100 and 100 to 1;
LP>OK - Being the perpetual newbie I am, let's go ahead and
LP>get the dumb approach over with (but it /does/ meet the
LP>requirement :-) ...
LP>#include
LP>char d[]="1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n\ 11
LP>\n12\n13\n14\n15\n16\n17\n18\n19\n20\n\ 21
LP>\n22\n23\n24\n25\n26\n27\n28\n29\n30\n\ 31
LP>\n32\n33\n34\n35\n36\n37\n38\n39\n40\n\ 41
LP>\n42\n43\n44\n45\n46\n47\n48\n49\n50\n\ 51
LP>\n52\n53\n54\n55\n56\n57\n58\n59\n60\n\ 61
LP>\n62\n63\n64\n65\n66\n67\n68\n69\n70\n\ 71
LP>\n72\n73\n74\n75\n76\n77\n78\n79\n80\n\ 81
LP>\n82\n83\n84\n85\n86\n87\n88\n89\n90\n\
LP>91\n92\n93\n94\n95\n96\n97\n98\n99\n100\n\
LP>99 \n98\n97\n96\n95\n94\n93\n92\n91\n90\n\ 89
LP>\n88\n87\n86\n85\n84\n83\n82\n81\n80\n\ 79
LP>\n78\n77\n76\n75\n74\n73\n72\n71\n70\n\ 69
LP>\n68\n67\n66\n65\n64\n63\n62\n61\n60\n\ 59
LP>\n58\n57\n56\n55\n54\n53\n52\n51\n50\n\ 49
LP>\n48\n47\n46\n45\n44\n43\n42\n41\n40\n\ 39
LP>\n38\n37\n36\n35\n34\n33\n32\n31\n30\n\ 29
LP>\n28\n27\n26\n25\n24\n23\n22\n21\n20\n\ 19
LP>\n18\n17\n16\n15\n14\n13\n12\n11\n10\n\ 9 \n8 \n7 \n6
LP>\n5 \n4 \n3 \n2 \n1";
LP>int main(void)
LP>{
LP> puts(d);
LP> return 0;
LP>}
LP>I suppose if I wanted to obfuscate it more, it could be in binary and
LP>written to a block of allocated memory, but it's been too long a
LP>day already banging my head against the Legato Networker
LP>wall to try and think much more... I am sure there are FAR
LP>more clever ways to do it.
LP>--
LP> -- Len Philpot -> len{at}philpot.org <--
LP> ------ > -----> http://philpot.org/ <--
LP>--- BBBS/LiI v4.01 Flag-5
þ CMPQwk 1.42 999
--- Maximus/2 3.01
LP> * Origin: Prism's_Point (1:261/38.1)* Origin: COMM Port OS/2 juge.com 204.89.247.1 (281) 980-9671 (1:106/2000) SEEN-BY: 633/267 270 @PATH: 106/2000 633/267 |
|
| SOURCE: echomail via fidonet.ozzmosis.com | |
Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.