Solved

URGENT: i'm in test, need help with "FOR"

Posted on 2003-03-24
Medium Priority
139 Views
hi, i'm in test right now, and i need help with "FOR", i need to display the folowing:
1
12
123
1234
12345

i don´t have idea of how to do this useing "FOR". plz send me the code lines. Need'em now!
0
Question by:israc
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 4
• 3
• 3

LVL 6

Expert Comment

ID: 8195840
If experts at EE arent allowed to help with homework, I seriously doubt we are allowed to help you cheat on a test...
0

LVL 15

Expert Comment

ID: 8197487
le triangle de Pascal ;-)
or some form of it

then you increment and print 1 and 2
then you increment and print 1, 2 and 3
this incrementation-printout is repeated a total of 4 times

doesn't this evoke something to you ?

print-out value 1 (let's say i=1)
repeating 4 times
increment j
repeating j times (k=1..i)
printout value k

No ?

Nothing ?

And what if I told you this can be solved with two FOR loops ?

what if I told you :

j:=0;
for i:=1 to 5 Do
Begin
Inc(j);
for k:=1 to j Do Write(k,' ');
WriteLn;
End; // for i
0

LVL 15

Expert Comment

ID: 8212549
it would be fine if you returned to close this question :/
0

Accepted Solution

jonathankopplainstain earned 285 total points
ID: 8219634
u have to declare var:
ren,blank,num:integer;
begin
for ren:=1 to 5 do
begin
for blank:=1 to 5-ren do
write (' ');
for num:=5 downto 5-ren+1 do
write(num);
writeln;
END.

Jonathan Kopplainstain
0

LVL 15

Expert Comment

ID: 8219908
this (surprisingly) accepted solution is completely rigid and unable to write 6 lines, 7 lines, N lines...

... and doesn't teach you the logic behind the triangle.

Completely useless
0

LVL 6

Expert Comment

ID: 8220008
Especially since on top of all that, it's incorrect.  The last for loop reads:

for num := 5 downto 5 - ren + 1 do
write(num);

When it should be:

for num := 1 to ren do
write(num);
0

Expert Comment

ID: 8225015
This is the complete program. Do it and try it. Then tell me anything u want.

PROGRAM triangle;
USES
crt;
VAR
blank,ren,num:integer;
BEGIN
clrscr;
FOR ren:=1 to 5 do
begin
for blank:=1 to 5-ren do
write(' ');
for num:=5 downto 5-ren+1 do
write(num);
writeln;
end;
END.

Jonathan Kopplainstain
0

LVL 6

Expert Comment

ID: 8225623
I don't need to try it.  I can tell from looking that it will output:

5
54
543
5432
54321
0

Expert Comment

ID: 8228265
Oops! U r rigth, i have to apoligize for this terrible mistake, i dunno why "israc" accepted this answer.

Jon Kopplainstain
0

LVL 15

Expert Comment

ID: 8228315
me neither 8-))))
0

Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In the absence of a fully-fledged GPO Management product like AGPM, the script in this article will provide you with a simple way to watch the domain (or a select OU) for GPOs changes and automatically take backups when policies are added, removed o…
This article will show how Aten was able to supply easy management and control for Artear's video walls and wide range display configurations of their newsroom.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses
Course of the Month13 days, 6 hours left to enroll