• Status: Solved
• Priority: Medium
• Security: Public
• Views: 140

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

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
israc
• 4
• 3
• 3
1 Solution

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

Commented:
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

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

Commented:
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

Commented:
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

Commented:
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

Commented:
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

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

5
54
543
5432
54321
0

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

Jon Kopplainstain
0

Commented:
me neither 8-))))
0

## Featured Post

• 4
• 3
• 3
Tackle projects and never again get stuck behind a technical roadblock.