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

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
Asked:
israc
  • 4
  • 3
  • 3
1 Solution
 
MannSoftCommented:
If experts at EE arent allowed to help with homework, I seriously doubt we are allowed to help you cheat on a test...
0
 
VGRCommented:
le triangle de Pascal ;-)
or some form of it

as you can see, you start with i:=1 and print 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
 
VGRCommented:
it would be fine if you returned to close this question :/
0
Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

 
jonathankopplainstainCommented:
here's the answer:
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;
     readln;
END.

if u have any question plz post a comment.
Jonathan Kopplainstain
0
 
VGRCommented:
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
 
MannSoftCommented:
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
 
jonathankopplainstainCommented:
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;
        readln;
END.

Jonathan Kopplainstain
0
 
MannSoftCommented:
I don't need to try it.  I can tell from looking that it will output:

    5
   54
  543
 5432
54321
0
 
jonathankopplainstainCommented:
Oops! U r rigth, i have to apoligize for this terrible mistake, i dunno why "israc" accepted this answer.

Jon Kopplainstain
0
 
VGRCommented:
me neither 8-))))
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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