求sum=d+dd+ddd+……+dd...d(n个d),其中d为1-9的数字.

来源:学生作业帮助网 编辑:作业帮 时间:2024/05/04 15:41:09
求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的数字.

求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