Program 2

Object:
Write a program to display Square and Cube of first Ten natural numbers.

Program:
10 CLS
20 FOR A= 1 TO 10
30 PRINT "Number", "Square ", " Cube"
40 PRINT A , A*A , A*A*A
50 NEXT A
60 END
RUN

Explanation:

  • Line 10 use to clear screen for program display.
  • Line 20 using FOR Loop ( repeat the execution of instruction between FOR- NEXT as range given with FOR). Variable A is holding tge range of number the loop execute the instructions
  • Line 30 simply print the words Number, Square, Cube
  • Line 40 is a formula written to display square and cube with the given number which is placed in variable A.
  • Line 50 always come with FOR loop as this line inform the interpretor to go back to Line having FOR statement to check the range given to execute the instruction between FOR-NEXT .
  • Line 80 use when the range given is over then to finish the execution of the program.
Output:
        Do u like to try to write the output of this program.....? Try it and write in comment box

1 comment:

  1. Output:
    Number Square Cube
    1 1 1
    2 4 8
    3 9 27
    4 16 64
    5 25 75
    6 36 216
    7 49 343
    8 64 512
    9 81 729
    10 100 1000

    ReplyDelete