| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | Re: [C] C Puzzles |
From: "Len Philpot"
> 2. Write a C program without using any loop (if, for, while etc) to print
> numbers from 1 to 100 and 100 to 1;
OK - Being the perpetual newbie I am, let's go ahead and get the dumb
approach over with (but it /does/ meet the requirement :-) ...
#include
char d[]="1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n\ 11
\n12\n13\n14\n15\n16\n17\n18\n19\n20\n\ 21
\n22\n23\n24\n25\n26\n27\n28\n29\n30\n\ 31
\n32\n33\n34\n35\n36\n37\n38\n39\n40\n\ 41
\n42\n43\n44\n45\n46\n47\n48\n49\n50\n\ 51
\n52\n53\n54\n55\n56\n57\n58\n59\n60\n\ 61
\n62\n63\n64\n65\n66\n67\n68\n69\n70\n\ 71
\n72\n73\n74\n75\n76\n77\n78\n79\n80\n\ 81
\n82\n83\n84\n85\n86\n87\n88\n89\n90\n\
91\n92\n93\n94\n95\n96\n97\n98\n99\n100\n\
99 \n98\n97\n96\n95\n94\n93\n92\n91\n90\n\ 89
\n88\n87\n86\n85\n84\n83\n82\n81\n80\n\ 79
\n78\n77\n76\n75\n74\n73\n72\n71\n70\n\ 69
\n68\n67\n66\n65\n64\n63\n62\n61\n60\n\ 59
\n58\n57\n56\n55\n54\n53\n52\n51\n50\n\ 49
\n48\n47\n46\n45\n44\n43\n42\n41\n40\n\ 39
\n38\n37\n36\n35\n34\n33\n32\n31\n30\n\ 29
\n28\n27\n26\n25\n24\n23\n22\n21\n20\n\ 19
\n18\n17\n16\n15\n14\n13\n12\n11\n10\n\ 9 \n8 \n7 \n6 \n5 \n4 \n3
\n2 \n1";
int main(void)
{
puts(d);
return 0;
}
I suppose if I wanted to obfuscate it more, it could be in binary and
written to a block of allocated memory, but it's been too long a day
already banging my head against the Legato Networker wall to try and think
much more... I am sure there are FAR more clever ways to do it.
--
-- Len Philpot -> len{at}philpot.org <--
------ > -----> http://philpot.org/ <--
--- BBBS/LiI v4.01 Flag-5
* Origin: Prism's_Point (1:261/38.1)SEEN-BY: 633/267 270 @PATH: 261/38 123/500 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™.