Εθνικό Μετσόβιο Πολυτεχνείο Σχολή Ηλεκτρολόγων Μηχανικών και Μηχανικών Υπολογιστών ΠΡΟΓΡΑΜΜΑΤΙΣΜΟΣ ΗΛΕΚΤΡΟΝΙΚΩΝ ΥΠΟΛΟΓΙΣΤΩΝ Προέλευση της Pazcal Διδάσκοντες: Στάθης Ζάχος (zachos@cs.ntua.gr) Νίκος Παπασπύρου (nickie@softlab.ntua.gr) Δημήτρης Φωτάκης fotakis@cs.ntua.gr)
Άδεια Χρήσης Το παρόν εκπαιδευτικό υλικό υπόκειται σε άδειες χρήσης Creative Commons. Για εκπαιδευτικό υλικό, όπως εικόνες, που υπόκειται σε άδεια χρήσης άλλου τύπου, αυτή πρέπει να αναφέρεται ρητώς.
Ασκήσεις (i) PROGRAM Hello1() WRITELN("hello world"); PROGRAM Hello2() WRITELN("hello ", "world"); PROGRAM Hello3() WRITE("hello "); WRITELN("world"); PROGRAM Hello4() WRITE("hello world"); WRITELN(); 3 25
Ασκήσεις (Pascal) (i) program Hello1(output); writeln('hello world') end. program Hello2(output); writeln('hello ', 'world') end. program Hello3(output); write('hello '); writeln('world') end. program Hello4(output); write('hello world'); writeln end. 4 26
Ασκήσεις (C) (i) #include <stdio.h> void main () printf("hello world\n"); #include <stdio.h> void main () #include <stdio.h> void main () printf("hello " "world\n"); #include <stdio.h> printf("hello "); void main () printf("world\n"); printf("hello world"); printf("\n"); 5 27
Ασκήσεις (ii) PROC hello() WRITELN("hello world"); PROC hello() PROGRAM Hello5() WRITELN("hello world"); hello(); hello(); hello(); hello(); PROGRAM Hello6() int i; FOR(i,1 TO 20) hello(); 6 28
Ασκήσεις (Pascal) (ii) program Hello5(output); procedure hello; writeln('hello world') end; program Hello6(output); hello; hello; hello; var i hello : integer; end. procedure hello; writeln('hello world') end; for i:=1 to 20 do hello end. 7 29
Ασκήσεις (C) (ii) #include <stdio.h> void hello() #include <stdio.h> printf("hello world\n"); void hello() void main() printf("hello world\n"); hello(); hello(); hello(); hello(); void main() int i; for (i=0; i<20; i++) hello(); 8 30
Ασκήσεις (iii) int i; PROC num_hello() WRITELN(i, " hello world"); PROGRAM Hello7() const int n = 20; FOR(i,1 TO n) num_hello(); 9 31
Ασκήσεις (Pascal) (iii) program Hello7(output); const n = 20; var i : integer; procedure num_hello; writeln(i, ' hello world') end; for i:= 1 to n do num_hello end. 10 32
Ασκήσεις (C) (iii) #include <stdio.h> const int n=20; int i; void num_hello() printf("%d hello world\n", i); void main() for (i=0; i<n; i++) num_hello(); 11 33
Ασκήσεις (iv) PROC hello() WRITELN("hello world"); PROGRAM Hello9() int i,n; WRITELN("Give number of greetings ", "then press <enter>:"); n = READ_INT(); FOR(i,1 TO n) hello(); 12 34
Ασκήσεις (Pascal) (iv) program Hello9(input,output); var i,n : integer; procedure hello; writeln('hello world') end; writeln('give number of greetings ', 'then press <enter>:'); read(n); for i:= 1 to n do hello end. 13 35
Ασκήσεις (C) (iv) #include <stdio.h> void hello() printf("hello world\n") void main() int i,n; printf("give number of greetings " "then press <enter>:"); scanf("%d", &n); for (i=0; i<n; i++) hello(); 14 36
Ασκήσεις (v) PROC hello() WRITELN("hello world"); PROGRAM Hello10() int i,n; WRITELN("Give number of greetings ", "then press <enter>:"); n = READ_INT(); if (n < 0) WRITELN("# is negative"); else FOR(i,1 TO n) hello(); 15 37
Ασκήσεις (Pascal) (v) program Hello10(input,output); var i,n : integer; procedure hello; writeln('hello world') end; writeln('give number of greetings ', 'then press <enter>:'); readln(n); if n < 0 then writeln('# is negative') else for i:= 1 to n do hello end. 16 38
Ασκήσεις (C) (v) #include <stdio.h> void hello() printf("hello world\n"); void main() int i,n; printf("give number of greetings " "then press <enter>"); scanf("%d\n",&n); if (n<0) printf("#is negative\n"); else for (i=0;i<n;i++) hello(); 17 39
Χρηματοδότηση Το παρόν εκπαιδευτικό υλικό έχει αναπτυχθεί στα πλαίσια του εκπαιδευτικού έργου του διδάσκοντα. Το έργο «Ανοικτά Ακαδημαϊκά Μαθήματα» του ΕΜΠ έχει χρηματοδοτήσει μόνο την αναδιαμόρφωση του υλικού. Το έργο υλοποιείται στο πλαίσιο του Επιχειρησιακού Προγράμματος «Εκπαίδευση και Δια Βίου Μάθηση» και συγχρηματοδοτείται από την Ευρωπαϊκή Ένωση (Ευρωπαϊκό Κοινωνικό Ταμείο) και από εθνικούς πόρους.