Page 1 of 1

Try it yourself

Posted: Thu Mar 06, 2014 8:34 pm
by zprogrammer
Technical puzzle

Below code in REXX generates prime numbers present between 1 to 1000.
Try to solve the same puzzle in Cobol.If you are able to solve in Cobol try a different language.

See how many languages you could solve the below problem ;)

Code: Select all

/*REXX*/
DO Y = 1000 TO 1 BY -1
   N = 0
   DO X = 1 TO 1000 BY +1
      Z = INDEX(Y/X,'.')
      IF Z = 0 THEN DO
         N     = N+1
         Y     = RIGHT(Y,4)
      END
   END
   IF N<=2 THEN DO
      SAY Y  'IS A PRIME NUMBER'
   END
END

Re: Try it yourself

Posted: Thu Mar 06, 2014 10:01 pm
by zprogrammer
Got to break my fingers before posting next time :mrgreen: