WAP to 1+11+111+..........+n
#include <iostream>
using namespace std;
int main() {
int n;
cout << "Enter the value of n: ";
cin >> n;
int s = 0;
int term = 1;
int multiplier = 1;
for (int i = 1; i <= n; i++) {
s += term;
multiplier *= 10;
term = term * 10 + 1;
}
cout << "The sum of the series is: " << s << endl;
return 0;
}
Output 1:-
Enter the value of n: 2
the sum of the series is: 12
Output 2:-
Enter the value of n: 5
the sum of the series is: 12345