求求Sn=a+aa+aaa+…+aa…a(n个a)和
作者:互联网
例如:1 + 11 + 111 + 1111(n = 4) = ?
#include<iostream>
using namespace std;
int main()
{
int a, n, sum = 0, num = 0, i = 0;
cout<<"输入a 和 n :";
cin>>a>>n;
while(i < n)
{
num = num + a;
sum = sum + num;
a = a * 10;
i++;
}
cout<<sum;
return 0;
}
标签:aa,aaa,cout,int,sum,num,Sn,main 来源: https://blog.csdn.net/KO812605128/article/details/123146100