2025-03-06 22:46:33 +08:00

25 lines
541 B
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*-------------------------------------------------------
编程求s=a+aa+aaa+aaaa+aa…a的值。其中a为一个数字3+33+333+3333+33333要求a以及所加数字个数n由键盘输入,示例中a=3,n=5。使用for
-------------------------------------------------------*/
#include <stdio.h>
main()
{
int a,n,s,i,t;
s=t=0;
printf("请输入数字a:");
scanf("%d",&a);
printf("请输入求和的项数n:");
scanf("%d",&n);
/**********Program**********/
t = a;
for(i=0;i<n;i++){
s += t;
t*=10;
t+=a;
}
/********** End **********/
printf("s=%d\n",s);
}