Skip to content

Latest commit

 

History

History
20 lines (18 loc) · 370 Bytes

18.md

File metadata and controls

20 lines (18 loc) · 370 Bytes

题目:求s=a+aa+aaa+aaaa+aa...a的值,其中a是一个数字。例如2+22+222+2222+22222(此时共有5个数相加),几个数相加由键盘控制。

#include<stdio.h>

int main()
{
	int a, n;
	scanf("%d %d", &a, &n);
	int s = 0;
	int tmp = a;
	for (int i = 0; i < n; ++i)
	{
		s += tmp;
		tmp = tmp * 10 + a;
	}
	printf("a+aa+...=%d", s);

	return 0;
}