RSS Forums RSS
Please support our Pascal and Delphi advertiser: Programming Forums

Turbo pascal Homework..

Join Date: May 2006
Posts: 2
Reputation: salgau_catalin is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
salgau_catalin's Avatar
salgau_catalin salgau_catalin is offline Offline
Newbie Poster

Re: Turbo pascal Homework..

  #2  
May 24th, 2006
for the first one, you could use this:
uses crt;
var k,i,j:integer;
begin
 clrscr;
 readln(k);
 for i:=1 to k do
  begin
   for j:=1 to k-i do
    write(' ');
   for j:=1 to i do
    write(j,' ');
   writeln;
  end;
 for i:=k downto k do
  begin
   for j:=1 to k-i do
    write(' ');
   for j:=i downto 1 do
    write(j,' ');
   writeln;
  end;
 readkey;
end.

for the second one, there are a lot of methods to reach the result.
thirst one I can think of is:
var s:string;
    i:byte;
begin
 readln(s);
 for i:=length(s) downto 1 do
  write(s[i]);
 writeln;
end.
as you can see, no explicit <arrays>
strings are actually arrays.
you could also do it with just one variable. the one with the text.
Reply With Quote  
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 11:04 pm.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC