Wap to find the sum of square of odd numbers upto 10 in qbasic?
Answers
Answered by
9
Language:
Qbasic
Program:
CLS
sum=0
FOR i =0 TO 10 STEP 2
sum=sum+i^2
NEXT i
PRINT I
END
Output:
Consider the attachment.
Explanation:
- Line 1: Cleans screen.
- Line 2: Initializes sum, the variable where we are gonna store the odd square's values.
- Line 3: Starts a loop of odd numbers.
- Line 4: Adds squared sum of that odd number in sum every time the loop runs.
- Line 5: Prints the final sum (out of the loop, the final value of sum).
- Line 6: Ends the loop.
Attachments:
Similar questions