?
Solved

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

Posted on 2003-03-24
10
Medium Priority
?
139 Views
Last Modified: 2010-04-16
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
Comment
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
  • Learn & ask questions
  • 4
  • 3
  • 3
10 Comments
 
LVL 6

Expert Comment

by:MannSoft
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

by:VGR
ID: 8197487
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
 
LVL 15

Expert Comment

by:VGR
ID: 8212549
it would be fine if you returned to close this question :/
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 

Accepted Solution

by:
jonathankopplainstain earned 285 total points
ID: 8219634
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
 
LVL 15

Expert Comment

by:VGR
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

by:MannSoft
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

by:jonathankopplainstain
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;
        readln;
END.

Jonathan Kopplainstain
0
 
LVL 6

Expert Comment

by:MannSoft
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

by:jonathankopplainstain
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

by:VGR
ID: 8228315
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.

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

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question