944,036 Members | Top Members by Rank

Ad:
May 19th, 2006
0

Turbo pascal Homework..

Expand Post »
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..
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
matabor is offline Offline
3 posts
since May 2006
May 24th, 2006
0

Re: Turbo pascal Homework..

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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
salgau_catalin is offline Offline
2 posts
since May 2006
May 30th, 2006
0

Re: Turbo pascal Homework..

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:
Reputation Points: 10
Solved Threads: 0
Newbie Poster
matabor is offline Offline
3 posts
since May 2006
May 30th, 2006
0

Re: Turbo pascal Homework..

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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
matabor is offline Offline
3 posts
since May 2006
Feb 27th, 2008
0

Re: Turbo pascal Homework..

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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
manutd4life230 is offline Offline
11 posts
since Feb 2008
Feb 27th, 2008
0

Re: Turbo pascal Homework..

What!!??

This thread is two years old.
Featured Poster
Reputation Points: 1140
Solved Threads: 229
Postaholic
Duoas is offline Offline
2,039 posts
since Oct 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Pascal and Delphi Forum Timeline: Stringgrid coloring problem
Next Thread in Pascal and Delphi Forum Timeline: resource file error





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC