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
12
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
- 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
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