wap to print all odd numbers in a user given range in qbasic
Answers
Answered by
4
The given problem is solved using language - QBASIC.
CLS
INPUT "Enter starting limit - "; A
INPUT "Enter ending limit - "; B
SUM = 0
FOR I = A TO B
IF I MOD 2 <> 0 THEN
SUM = SUM + I
END IF
NEXT I
PRINT "Sum of all the odd numbers in the given range is:"; SUM
END
- Accept the range from the user.
- Initialize sum = 0.
- Iterate through each numbers in the range.
- If the number is odd, add the number to sum.
- Display the value of the variable sum.
See the attachment for output.
Attachments:
Similar questions