Computer Science, asked by ayushghosh9710, 12 hours ago

Write a program in QBASIC to find the sum of the following series :S = 1 + 11 + 111 + 1111 + .. n ( where n is number of terms)

Answers

Answered by anindyaadhikari13
12

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

The given problem is solved using language - QBASIC.

CLS

INPUT "Enter limit - "; N

A = 1

SUM = 0

FOR I = 1 TO N

   SUM = SUM + A

   A = A * 10 + 1

NEXT I

PRINT "Sum of the series: "; SUM

END

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

  • Initialise SUM = 0, A = 1
  • Accept the limit from the user, say n.
  • Repeat I = 1 to N.
  • Add 'A' to 'SUM'.
  • Multiply 'A' by 10 and add 1 to it to get the next term.
  • Display the sum.

See attachment for output.

Attachments:
Answered by aashishkarn37
3

Explanation:

CLS

S = 0 , A = 1

FOR I = 1 TO N

A = A × 10 + 1

S = S + A

NEXT I

PRINT S

END

Similar questions