Hi guys :)

I've just learn programming in turbo pascal, and my teacher made an assignment to make pyramid of numbers as this:

1
   1 2
  1 2 3
  3 2 1
   2 1
    1

so far i've only come up as this:

uses crt;

var i,j,k : byte;

begin
  clrscr;

  for i := 1 to 3 do
  begin

    for j := 3 downto i do
    begin
      inc (k);
      if i = 2 then k:=3;
      gotoxy(i+k,j); write(i);
    end;

  end;

  readkey;
end.

this is the output:

1
   1 2
  1  2 3

--------------------(2)------------------
And another one:

Make the word : "Hello" to "olleH"

do I have to use arrays on this one?

I'm totally blank on this one , please point me to the right direction..
----------------------------------------

Can anybody help me?

thanks..

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.

Oh, I see..

So strings are actualy arrays. I just knew that, thanks :)
I thought I had to make make an array manualy, then use some kind of sort algorithm :eek:

And for the piramid that was a brain teaser.. That was briliant, thank you so much salgau_catalin you saved my ass :cheesy:

My teacher made me make an inversed pyramid..

Heres the code, if anyone needs it:

uses crt;

const
  pert ='Batas diamond: ';


var
  i, j, k,bts: Byte;

begin

  gotoxy(30,5);write(pert); gotoxy(30+length(pert),5);read(bts);

  for i := bts downto 1 do
  begin
    inc(k);
    gotoxy(1, k);
    for j := 1 to i do
    begin
      Write(j);
    end;
  end;
  k :=0;
  for i := 1 to bts do
  begin
    Inc(k);
    gotoXY(1,k + bts);
    for j := 1 to i do
    begin
      Write(j);
    end;
  end;
  k := 0;
  for i := bts downto 1 do
  begin
    Inc(k);
    gotoxy(k + bts,k);
    for j := i downto 1 do
    begin
      Write(j);
    end;
  end;
  k := 0;
  for i := bts downto 1 do
  begin
    Inc(k);
    gotoXY(k + bts,i + bts);
    for j := i downto 1 do
    begin
      Write(j);
    end;
  end;

  readkey;

end.

program to ask the user a username and a password
if pass and username good display OK
else
clear screen and reask the user for username and password again.
this will continue until good username and password entred.
thanks in advanced

What!!??

This thread is two years old.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.