Computer Science, asked by a071715, 1 month ago

wap to print all odd numbers in a user given range in qbasic

Answers

Answered by anindyaadhikari13
4

\textsf{\large{\underline{Solution}:}}

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

\textsf{\large{\underline{Logic}:}}

  • 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