0
votes

I have written an application which will write square with diagonal (from left side) - output:

+ * * * *
* + * * *
* * + * *
* * * + *
* * * * +

Code for first application:

PROGRAM cycle4;
USES  CRT;
VAR a,r,s:INTEGER;
BEGIN
  CLRSCR;    
  WRITE (‘Enter the number of lines :‘) ;
  READLN(a);
  FOR r:= 1 TO  a DO
  BEGIN
    FOR s:=1 TO a  DO 
      IF r =  s THEN WRITE(‘+‘) 
      ELSE WRITE(‘*‘)  ;
      WRITELN;
  END;
  READLN;
END.

And now I have to create an application which will write square with diagonal (from right side) - output:

* * * * +
* * * + *
* * + * *
* + * * *
+ * * * *

But I don't know how can I write it. Can you help me?

Thanks :)

1
Could you post your code of the first application? - demonplus
@demonplus i have posted it - user4653508
Are you sure that you wrote the first code your self? Or did your teacher give it to you and asked if you could alter it? :) - MyGGaN

1 Answers

3
votes

The line of code which defines the position of + sign is that:

IF r =  s THEN WRITE(‘+‘) 

and this is the only line you need to change:

IF r + s =  a + 1 THEN WRITE(‘+‘) 

I think this should work, check with Pascal compiler, haven't used it for about 10 years :)