| Programmieraufgaben Hier wird regelmäßig eine neue Programmieraufgabe gestellt, die dann gelöst werden soll und in Zusammenarbeit mit den Moderatoren auch besprochen werden kann. |
Diskussion: Zahlenreihe im Forum Programmieraufgaben, in der Kategorie Code Kitchen; Anzeige Hi, also hier meine erste Aufgabe (gar nicht leicht sich da was auszudenken ;-) Aufgabe: Es sind alle Zahlen ...
![]() |
| | #1 (permalink) |
| Anzeige Hi, also hier meine erste Aufgabe (gar nicht leicht sich da was auszudenken ;-) Aufgabe: Es sind alle Zahlen von 1 bis 100 auf den Bildschirm zu "zaubern", allerdings OHNE Schleifen und OHNE Gotos im Code zu benutzen. Das ganze dürfte selbst für Anfänger leicht zu lösen sein. Hier meine Lösung: (Zum lesen einfach mit STRG+C und STRG+V in einen Editor kopieren oder bei diesem Beitrag auf Zitieren klicken.) #include <iostream> using namespace std; void zahlenreihe(void); int counter = 0; int main(void) { zahlenreihe(); } void zahlenreihe(void) { counter++; cout << counter << endl; if(counter < 100) zahlenreihe(); } Happy Coding, Xalon | |
| | |
| | #2 (permalink) |
| Senior Member Registriert seit: 03.09.05 ![]() Likes: 0 | Auch ohne Rekursion? (seltsame Aufgabe, btw) Edit: Ich glaube, alles nacheinander auszugeben ist auch nicht gemeint Edit2: Ich sehe gerade, dass Rekursion wohl erlaubt war, obwohl es eigentlich das selbe ist wie gotos/schleifen.. |
| | |
| HaBOT | - Anzeige - |
| |
| | #3 (permalink) |
| Senior Member Registriert seit: 23.12.03 ![]() Likes: 0 | #/bin/bash echo 1 echo 2 echo 3 echo 4 .... return 0 |
| | |
| | #4 (permalink) |
| Registriert seit: 02.11.04 ![]() Likes: 0 | Bisel Ruby-Eval-Zauberei gefällig? Code: # Ruby 1.8.04 i = 1 cmd = "puts i.to_s; i += 1;" * 99 eval(cmd) EDIT: Vll so etwas eleganter: Code:
i = 1
eval("puts (i += 1);" * 99) |
| | |
| | #5 (permalink) | |
| Themenstarter | Zitat:
Aber ok,nächstes mal bekommt ihr was schwierigeres,ich weiß auch schon was Rekursion ist natürlich erlaubt. @silenced:Naja,nicht sehr elegant Xalon | |
| | |
| | #6 (permalink) |
| Senior Member Registriert seit: 23.12.03 ![]() Likes: 0 | :-) Naja, so ganz ohne Schleife.... geht´s ja doch nicht :-) war ja auch mehr als scherz gemeint, aber alle achtung für M@rex ;-) alternativ |
| | |
| | #7 (permalink) |
| Member of Honour ![]() Registriert seit: 28.05.03 ![]() Likes: 1 | Code: #!/usr/bin/perl my @Zahlen = 1..100; print "@Zahlen";
__________________ http://livehabo.hackerboard.de | http://livebb.sourceforge.net |
| | |
| | #8 (permalink) |
| Senior Member Registriert seit: 26.03.06 ![]() Likes: 16 | Code:
System.out.println("1");
System.out.println("2");
System.out.println("3");
System.out.println("4");
System.out.println("5");
System.out.println("6");
System.out.println("7");
System.out.println("8");
System.out.println("9");
System.out.println("10");
System.out.println("11");
System.out.println("12");
System.out.println("13");
System.out.println("14");
System.out.println("15");
System.out.println("16");
System.out.println("17");
System.out.println("18");
System.out.println("19");
System.out.println("20");
System.out.println("21");
System.out.println("22");
System.out.println("23");
System.out.println("24");
System.out.println("25");
System.out.println("26");
System.out.println("27");
System.out.println("28");
System.out.println("29");
System.out.println("30");
System.out.println("31");
System.out.println("32");
System.out.println("33");
System.out.println("34");
System.out.println("35");
System.out.println("36");
System.out.println("37");
System.out.println("38");
System.out.println("39");
System.out.println("40");
System.out.println("41");
System.out.println("42");
System.out.println("43");
System.out.println("44");
System.out.println("45");
System.out.println("46");
System.out.println("47");
System.out.println("48");
System.out.println("49");
System.out.println("50");
System.out.println("51");
System.out.println("52");
System.out.println("53");
System.out.println("54");
System.out.println("55");
System.out.println("56");
System.out.println("57");
System.out.println("58");
System.out.println("59");
System.out.println("60");
System.out.println("61");
System.out.println("62");
System.out.println("63");
System.out.println("64");
System.out.println("65");
System.out.println("66");
System.out.println("67");
System.out.println("68");
System.out.println("69");
System.out.println("70");
System.out.println("71");
System.out.println("72");
System.out.println("73");
System.out.println("74");
System.out.println("75");
System.out.println("76");
System.out.println("77");
System.out.println("78");
System.out.println("79");
System.out.println("80");
System.out.println("81");
System.out.println("82");
System.out.println("83");
System.out.println("84");
System.out.println("85");
System.out.println("86");
System.out.println("87");
System.out.println("88");
System.out.println("89");
System.out.println("90");
System.out.println("91");
System.out.println("92");
System.out.println("93");
System.out.println("94");
System.out.println("95");
System.out.println("96");
System.out.println("97");
System.out.println("98");
System.out.println("99");
System.out.println("100"); |
| | |
| | #9 (permalink) |
| Senior Member Registriert seit: 28.08.05 ![]() Likes: 0 | ivegotmail war schneller |
| | |
| | #10 (permalink) |
| Moderator ![]() | Code: #!/bin/bash if [ ! $1 ] then number=1 else let number=$1+1 fi if [ $number -lt 101 ] then echo $number ./$0 $number fi |
| | |
| | #11 (permalink) |
| Moderator ![]() Registriert seit: 20.07.05 ![]() ![]() ![]() ![]() ![]() ![]() Likes: 202 | kommt zwar nicht an ruby ran, immerhin aber 32 Byte ![]() Code: 44 40 50 D4 0A 05 30 30 50 8A D4 B4 02 CD 21 58 8A D0 B4 02 CD 21 58 81 EC 8F 02 BB 01 01 53 C3 Code: .Model tiny
CSEG segment
org 100h
Begin:
inc sp
Ausgeben:
inc ax
push ax
aam
add ax,3030h
push ax
mov dl,ah
mov ah,02
int 21h
pop ax
mov dl,al
mov ah,02
int 21h
pop ax
sub sp,655
mov bx,offset Ausgeben
push bx
ret
CSEG ends
end Begin
__________________ Noch mal, für alle Pseudo-Geeks: 1+1=0. -> 10 wäre Überlauf! Selig, wer nichts zu sagen hat und trotzdem schweigt. |
| | |
| | #12 (permalink) |
| Registriert seit: 20.07.06 ![]() Likes: 21 | Und hier noch ein Beispiel in Python: Code: def zahlenreihe(n=0):
print n
if n==100:
raise SystemExit()
else:
zahlenreihe(n+1) |
| | |
| | #13 (permalink) |
| Und das ganz noch in PHP(falls erlaubt): PHP-Code: | |
| | |
| | #14 (permalink) |
| Registriert seit: 12.08.06 ![]() Likes: 0 | Code: class zahl {
public static void main(String[] args) {
int i=0;
inc(i);
}
static void inc(int i){
if(i<100){
i++;
System.out.println(i);
inc(i);
}
}
} |
| | |
| | #15 (permalink) |
| die lösung von CDW is natürlich state of the art ![]() und für mich ein guter einstiegspunkt, sich endlich mal an assembler heran zu wagen EDIT: @CDW: nur für mich als kleiner einblick: wie lange hast du dafür gebraucht? .. is das sowas wie routine für jemanden, der assembler kann? | |
| | |
![]() |
| - Anzeige - | |
| |
| Themen-Optionen | |
| Ansicht | |
| |
Ähnliche Themen | ||||
| Thema | Autor | Forum | Antworten | Letzter Beitrag |
| rekursive Zahlenreihe | CDW | Programmieraufgaben | 22 | 08.06.11 12:01 |