Joachim Mohr   Mathematik Musik Delphi

Weitere Aufgaben

1. Aufgabe Was wird bei folgendem Programm ausgedruckt? (Buchstabengenau!)


procedure TForm1.Button1Click(Sender: TObject);
  var a, b, c: integer;
begin
  a := 1; b := 2; c := 3;
  memo1.Lines.Add('1. a) ' + inttostr(a) + ' ' + inttostr(b)+ ' ' + inttostr(c));
  a := a + 1; b := b + 2; c := c + 3;
  memo1.Lines.Add('1. b) ' + inttostr(a) + ' ' + inttostr(b)+ ' ' + inttostr(c));
  a := b + c; b := a + c; c := a + b;
  memo1.Lines.Add('1. c) ' + inttostr(a) + ' ' + inttostr(b)+ ' ' + inttostr(c));
  a := 2; a := a*a; a := a*a; a := a*a;
  memo1.Lines.Add('1. a) ' + inttostr(a))
end;


2. Aufgabe Schreibe ein Programm, das eine Wertetafel für f(x) = (1/4)x4 - (1/2)x2 in einem Memofeld ausgibt!

a) Mit einer "for"-schleife und für x= 0, 1, 2, ..., 8, 9, 10
b) Mit "repeat ... until"-Schleife und für x = 0; 0,1; 0,2; ... ; 3,9; 4
c) Mit "while"-Schleife und für x = 0; 2; 4; 6; ... ; 20



3. Aufgabe Was wird bei folgendem Programm berechnet (Rechenausdruck genügt)

procedure TForm1.Button1Click(Sender: TObject);
  var i: integer; r: real;
begin
  r := 0;
  for i := 1 to 100 do r := r + i/(i+1);
  memo1.lines.Add('2 a) ' + FloatToStr(r));
  r := 1;
  for i := 1 to 100 do r := r * i/(i+1);
  memo1.lines.Add('2 b) ' + FloatToStr(r));
end;





4. Aufgabe Schreibe ein Programm, das folgendes berechnet:
a) s = 1 + 1/4 + 1/9 + ... + 1/1002

b) p = 1*4*9*...*n2   (n soll in einem Editfeld eingegeben werden.)

c) s= 1 - 1/2 + 1/3 - 1/4 + ... - 1/10000. Hinweis zum Vorzeichen: Verwende eine Variable vz = 1 und ändere sie laufend mit vz := -vz!



5. Aufgabe Betrachte folgendes Programm?

procedure TForm1.Button1Click(Sender: TObject);
  var a,b,x: integer;
begin
 a := StrToInt(edit1.text);
 b := StrToInt(edit2.text);
 if a > b then Begin
   x := a;
   a := b;
   b := x;
 End;
 showmessage('Die beiden Zahlen sind ' +
              inttostr(a) + ' und ' + inttostr(b));
end;
a) Was ist die Ausgabe, wenn in edit1 die Zahl 5 und in edit2 die Zahl 10 steht?

b) Was ist die Ausgabe, wenn in edit1 die Zahl 10 und in edit2 die Zahl 5 steht?

c) Erläutere den "Witz" des Programms.

d) Was ändert sich, wenn das Programm folgendermaßen lautet:

procedure TForm1.Button1Click(Sender: TObject);
  var a,b,x: integer;
begin
 a := StrToInt(edit1.text);
 b := StrToInt(edit2.text);
 if a > b then Begin
   a := b;
   b := a;
 End;
 showmessage('Die beiden Zahlen sind ' +
              inttostr(a) + ' und ' + inttostr(b));
end;