C语言求Sn=a+aa+aaa+aaaa+aaaaa的前5项之和

参考资料:https://blog.csdn.net/jugger_am/article/details/79129597

#define _CRT_SECURE_NO_WARNING
#include 
#include 
int main() {
	//printf("请输入一个整数:");
	int a = 0;
	int b = 0;
	int n = 0;
	int tmp = 0;
	int sum = 0;
	scanf("%d%d", &a, &b);
	for (n = 0; n < b; n++) {
		tmp = tmp * 10 + a;
		sum = sum + tmp;
	}
	printf("%d\n", sum);
	system("pause");
return 0;
}

你可能感兴趣的:(C语言求Sn=a+aa+aaa+aaaa+aaaaa的前5项之和)