编程求和s=a+aa+aaa+...+aa....a。例如a=3,那么求s=3+33+333;若a=5,那么求s=5+55+555+5555+55555。(循环作业)

#include <iostream>

using  namespace std;

#include <cmath>

int main() {

int x = 0;

cout << "请输入一个正整数:" << endl;

cin >> x;

int m = x;

int z = x;

for (int i=1;i<=x-1; i++) {

m=m+ x * pow(10, i);

z = z + m;

}

cout << z <<endl;

return 0;

}

 

posted @ 2020-03-28 08:44  木屋小丑  阅读(1198)  评论(0)    收藏  举报