write qbasic program to find perimeter of 10 squares using for next loop
Answers
Question:
- WAP in QBASIC to print perimeter of a square using for-next loop
Answer:
CLS
FOR I=1 TO 10
PRINT "ENTER A SIDE IF A SQUARE"
INPUT S
P=4*S
PRINT "PERIMETER OF A SQUARE="+P
NEXT I
END
How does this code works?
In each iteration i.e. from 1 to 10 the program accepts a side of a square from the user and calculates the perimeter of the square. Then, finally prints the perimeter
Question:
- Write a QBASIC program to find perimeter of 10 squares using FOR NEXT loop.
Program:
This is an easy question. Read this post to get your answer.
Here is the program.
CLS
REM "Program to find perimeter of 10 squares"
FOR I = 1 TO 10
INPUT "Enter Side: ", A
P = 4*A
PRINT "Perimeter of the square is: "+P
PRINT "-------------------------------------------------"
NEXT I
END
Syntax of FOR LOOP:
FOR <VARIABLE> = <INITIAL_VAL> TO <FINAL_VAL> STEP <STEP_VAL>
STATEMENTS.....
NEXT <VARIABLE>
Note: The default step value is 1. So, no need of writing STEP 1 for continuous iteration.
Logic:
- In this program, we have created a loop that iterates 10 times and we have asked the user to enter the side of the square. Using formula, we have calculated the perimeter of square and it is displayed.