0

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

Rohit Gupta
  • 4,022
  • 20
  • 31
  • 41
user4653508
  • 23
  • 1
  • 3

1 Answers1

3

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

demonplus
  • 5,613
  • 12
  • 49
  • 68