Einzelnen Beitrag anzeigen

moritz

Registriert seit: 18. Apr 2003
1.037 Beiträge
 
#10

Re: Sternchenmuster erstellen

  Alt 9. Jan 2005, 18:23
Mein Vorschlag
Code:
program dreieck_links;
{$APPTYPE CONSOLE}

uses SysUtils;

var
  max, pos: Byte;

function StrMulti (chr: Char; cnt: Byte):String;
begin
  result := '';
  if cnt = 0 then exit;
  repeat
    result := result + chr;
  until length (result) = cnt;
end;

begin
  Write ('Wieviel Sterne: ');
  ReadLn (max);
  // Wir brauchen eine ungerade Anzahl, dass wir in der Mitte einen Stern bekommen
  if (max mod 2 = 0) then inc (max, 1);
  pos := max;

  repeat
    WriteLn (StrMulti (' ', Round ((max - pos) / 2) ) + StrMulti ('*', pos));
    Inc (pos, -2);
  until pos = 1;
  repeat
    WriteLn (StrMulti (' ', Round ((max - pos) / 2) ) + StrMulti ('*', pos));
    Inc (pos, 2);
  until pos > max;
  ReadLn;
end.
"Optimistisch ist diejenige Weltanschauung, die das Sein höher als das Nichts stellt und so die Welt und das Leben als etwas an sich Wertvolles bejaht."
Albert Schweitzer
  Mit Zitat antworten Zitat