求sum=d+dd+ddd+……+dd...d(n个d),其中d为1-9的数字.
来源:学生作业帮助网 编辑:作业帮 时间:2024/07/03 13:02:29
![求sum=d+dd+ddd+……+dd...d(n个d),其中d为1-9的数字.](/uploads/image/z/9430038-54-8.jpg?t=%E6%B1%82sum%3Dd%2Bdd%2Bddd%2B%E2%80%A6%E2%80%A6%2Bdd...d%28n%E4%B8%AAd%29%2C%E5%85%B6%E4%B8%ADd%E4%B8%BA1-9%E7%9A%84%E6%95%B0%E5%AD%97.)
求sum=d+dd+ddd+……+dd...d(n个d),其中d为1-9的数字.
求sum=d+dd+ddd+……+dd...d(n个d),其中d为1-9的数字.
求sum=d+dd+ddd+……+dd...d(n个d),其中d为1-9的数字.
调试通过的程序代码如下:
#include
main()
{
long n,d,x,sum=0;
scanf("%ld%ld",&n,&d);
x=d;
while(n>0){sum+=x; x=x*10+d; n--;}
printf("%ld\n",sum);
}
上面的程序运行结果如下:
5 1
12345
4 2
2468
4 3
3702