main(i){for(;i<101;i++)if(i%15<1)puts("FizzBuzz");else if(i%3<1)puts("Fizz");
else if(i%5<1)puts("Buzz");else printf("%d\n",i);}
printf
und puts
auch ohne Prototyp.int
als Rückgabewert.int
als Typ. Der erste Parameter ist argc und hier 1
. Keine Übergabeparameter.n;
vor der main ist wie int n = 0;
das geht auch mit arrays.main(i){for(;i<101;i++)i%15<1?puts("FizzBuzz"):i%3<1?puts("Fizz"):i%5<1?puts("Buzz"):printf("%d\n",i);}
Was wäre wenn wir die <1
weg bekommen?
Bedingung negieren, da !=0
ist gleich true
=> neu sortieren
main(i){for(;i<101;i++)i%15?i%3?i%5?printf("%d\n",i):puts("Buzz"):puts("Fizz"):puts("FizzBuzz");}
Was wäre wenn wir die mehrfachen Aufrufe von puts()
wegbekommen?
Kann man das auf einen puts
(für newline) und ein printf
reduzieren?
Bitte versucht es selbst: 15 min
if(i)puts("hallo");
(19) =>
i?puts("hallo"):0;
(18) =>
i&&puts("hallo");
(17)
if(!i)puts("hallo");
(20) =>
i||puts("hallo");
(17)
for x in range(1,101):print(("Fizz"if x%3<1else"")+("Buzz"if x%5<1else"")or x)
A number is a divisor of another number if it can divide into it with no remainder.
Print the positive divisors of each number from 1 to 100 inclusive, on their own line, with each divisor separated by a space.
j;main(i){for(;i<101;i++,puts(""))for(j=0;j++<i;)i%j||printf("%d ",j);}
Versucht mal ob ihr eine for Schleife weg bekommt.
j;main(i){for(;i<101;)printf(j++<i?i%j?"":"%d ":"
"+(j-=++i),j);}
\n
durch ein richtiges new line."\n"+(j-=++i)
ein Newline-String definiert und parallel j=0
und i++
. +0 auf den const char*
macht nichts.for(j=0,i=1;i<101;)write(j++<i?i%j?"":j+" ":(j-=++i)||"\n")
The Fibonacci numbers are a numerical sequence in which each number is the sum of the two preceding numbers:
0, 1, 1, 2, 3, 5, 8, 13 …
Print the first 31 Fibonacci numbers from F0 = 0 to F30 = 832040 (inclusive), each on a separate line.
l,f;main(h){for(;f<1000000;l=f,f+=h,printf("%d\n",h=l));}
Versuche die lange Konstante kürzer zu bekommen oder durch die Anzahl zu ersetzen.
Versuche eine Variable loszuwerden.
for(o=0,h=1;o<1e6;)print(h=(o+=h)-h)
a,b=0,1
while a<1e6:print(a);a,b=b,b+a
Mein Bildschirm https://meeten.statt-drosseln.de/b/mar-9pp-v9g-cu6