User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Pascal and Delphi section within the Software Development category of DaniWeb, a massive community of 391,549 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,536 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Pascal and Delphi advertiser:
Views: 2835 | Replies: 5
Reply
Join Date: May 2006
Posts: 3
Reputation: matabor is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
matabor's Avatar
matabor matabor is offline Offline
Newbie Poster

Help Turbo pascal Homework..

  #1  
May 19th, 2006
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..
AddThis Social Bookmark Button
Reply With Quote  
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  
Join Date: May 2006
Posts: 3
Reputation: matabor is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
matabor's Avatar
matabor matabor is offline Offline
Newbie Poster

Re: Turbo pascal Homework..

  #3  
May 30th, 2006
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:
Reply With Quote  
Join Date: May 2006
Posts: 3
Reputation: matabor is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
matabor's Avatar
matabor matabor is offline Offline
Newbie Poster

Re: Turbo pascal Homework..

  #4  
May 30th, 2006
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.
Reply With Quote  
Join Date: Feb 2008
Posts: 11
Reputation: manutd4life230 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
manutd4life230 manutd4life230 is offline Offline
Newbie Poster

Re: Turbo pascal Homework..

  #5  
Feb 27th, 2008
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
Reply With Quote  
Join Date: Oct 2007
Location: Cherry Hill, NJ
Posts: 1,809
Reputation: Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold 
Rep Power: 11
Solved Threads: 184
Featured Poster
Duoas's Avatar
Duoas Duoas is offline Offline
Posting Virtuoso

Re: Turbo pascal Homework..

  #6  
Feb 27th, 2008
What!!??

This thread is two years old.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb Pascal and Delphi Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the Pascal and Delphi Forum

All times are GMT -4. The time now is 9:10 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC