Write a program in C++ to find the sum of the series 1 +11 + 111 + 1111 + .. n terms
- برمجة سي بلس بلس
- برمجة
- 2021-05-12
- MarwaMohammed
الأجوبة
#include <iostream>
using namespace std;
int main()
{
int n, i, sum = 0;
int t = 1;
cout << "\n\n Display the sum of the series 1 +11 + 111 + 1111 + .. n terms:\n";
cout << "-------------------------------------------------------------------\n";
cout << " Input number of terms: ";
cin >> n;
for (i = 1; i <= n; i++)
{
cout << t << " ";
if (i < n)
{
cout << "+ ";
}
sum = sum + t;
t = (t * 10) + 1;
}
cout << "\n The sum of the series is: " << sum << endl;
}أسئلة مشابهة
القوائم الدراسية التي ينتمي لها السؤال
