Turbo pascal Homework..

Please support our Pascal and Delphi advertiser: Programming Forums - DaniWeb Sister Site
Reply

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

Turbo pascal Homework..

 
0
  #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:
Pascal and Delphi Syntax (Toggle Plain Text)
  1. 1
  2. 1 2
  3. 1 2 3
  4. 3 2 1
  5. 2 1
  6. 1
so far i've only come up as this:

Pascal and Delphi Syntax (Toggle Plain Text)
  1.  
  2. uses crt;
  3.  
  4. var i,j,k : byte;
  5.  
  6. begin
  7. clrscr;
  8.  
  9. for i := 1 to 3 do
  10. begin
  11.  
  12. for j := 3 downto i do
  13. begin
  14. inc (k);
  15. if i = 2 then k:=3;
  16. gotoxy(i+k,j); write(i);
  17. end;
  18.  
  19. end;
  20.  
  21. readkey;
  22. end.

this is the output:
Pascal and Delphi Syntax (Toggle Plain Text)
  1. 1
  2. 1 2
  3. 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..
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 2
Reputation: salgau_catalin is an unknown quantity at this point 
Solved Threads: 0
salgau_catalin's Avatar
salgau_catalin salgau_catalin is offline Offline
Newbie Poster

Re: Turbo pascal Homework..

 
0
  #2
May 24th, 2006
for the first one, you could use this:
Pascal and Delphi Syntax (Toggle Plain Text)
  1. uses crt;
  2. var k,i,j:integer;
  3. begin
  4. clrscr;
  5. readln(k);
  6. for i:=1 to k do
  7. begin
  8. for j:=1 to k-i do
  9. write(' ');
  10. for j:=1 to i do
  11. write(j,' ');
  12. writeln;
  13. end;
  14. for i:=k downto k do
  15. begin
  16. for j:=1 to k-i do
  17. write(' ');
  18. for j:=i downto 1 do
  19. write(j,' ');
  20. writeln;
  21. end;
  22. readkey;
  23. end.

for the second one, there are a lot of methods to reach the result.
thirst one I can think of is:
Pascal and Delphi Syntax (Toggle Plain Text)
  1. var s:string;
  2. i:byte;
  3. begin
  4. readln(s);
  5. for i:=length(s) downto 1 do
  6. write(s[i]);
  7. writeln;
  8. 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 Quick reply to this message  
Join Date: May 2006
Posts: 3
Reputation: matabor is an unknown quantity at this point 
Solved Threads: 0
matabor's Avatar
matabor matabor is offline Offline
Newbie Poster

Re: Turbo pascal Homework..

 
0
  #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 Quick reply to this message  
Join Date: May 2006
Posts: 3
Reputation: matabor is an unknown quantity at this point 
Solved Threads: 0
matabor's Avatar
matabor matabor is offline Offline
Newbie Poster

Re: Turbo pascal Homework..

 
0
  #4
May 30th, 2006
My teacher made me make an inversed pyramid..

Heres the code, if anyone needs it:

Pascal and Delphi Syntax (Toggle Plain Text)
  1.  
  2. uses crt;
  3.  
  4. const
  5. pert ='Batas diamond: ';
  6.  
  7.  
  8. var
  9. i, j, k,bts: Byte;
  10.  
  11. begin
  12.  
  13. gotoxy(30,5);write(pert); gotoxy(30+length(pert),5);read(bts);
  14.  
  15. for i := bts downto 1 do
  16. begin
  17. inc(k);
  18. gotoxy(1, k);
  19. for j := 1 to i do
  20. begin
  21. Write(j);
  22. end;
  23. end;
  24. k :=0;
  25. for i := 1 to bts do
  26. begin
  27. Inc(k);
  28. gotoXY(1,k + bts);
  29. for j := 1 to i do
  30. begin
  31. Write(j);
  32. end;
  33. end;
  34. k := 0;
  35. for i := bts downto 1 do
  36. begin
  37. Inc(k);
  38. gotoxy(k + bts,k);
  39. for j := i downto 1 do
  40. begin
  41. Write(j);
  42. end;
  43. end;
  44. k := 0;
  45. for i := bts downto 1 do
  46. begin
  47. Inc(k);
  48. gotoXY(k + bts,i + bts);
  49. for j := i downto 1 do
  50. begin
  51. Write(j);
  52. end;
  53. end;
  54.  
  55. readkey;
  56.  
  57. end.
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 11
Reputation: manutd4life230 is an unknown quantity at this point 
Solved Threads: 0
manutd4life230 manutd4life230 is offline Offline
Newbie Poster

Re: Turbo pascal Homework..

 
0
  #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 Quick reply to this message  
Join Date: Oct 2007
Posts: 1,952
Reputation: Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of 
Solved Threads: 214
Featured Poster
Duoas's Avatar
Duoas Duoas is offline Offline
Posting Virtuoso

Re: Turbo pascal Homework..

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

This thread is two years old.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Pascal and Delphi Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC