[{"createTime":1735734952000,"id":1,"img":"hwy_ms_500_252.jpeg","link":"https://activity.huaweicloud.com/cps.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=V1g3MDY4NTY=&utm_medium=cps&utm_campaign=201905","name":"华为云秒杀","status":9,"txt":"华为云38元秒杀","type":1,"updateTime":1735747411000,"userId":3},{"createTime":1736173885000,"id":2,"img":"txy_480_300.png","link":"https://cloud.tencent.com/act/cps/redirect?redirect=1077&cps_key=edb15096bfff75effaaa8c8bb66138bd&from=console","name":"腾讯云秒杀","status":9,"txt":"腾讯云限量秒杀","type":1,"updateTime":1736173885000,"userId":3},{"createTime":1736177492000,"id":3,"img":"aly_251_140.png","link":"https://www.aliyun.com/minisite/goods?userCode=pwp8kmv3","memo":"","name":"阿里云","status":9,"txt":"阿里云2折起","type":1,"updateTime":1736177492000,"userId":3},{"createTime":1735660800000,"id":4,"img":"vultr_560_300.png","link":"https://www.vultr.com/?ref=9603742-8H","name":"Vultr","status":9,"txt":"Vultr送$100","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":5,"img":"jdy_663_320.jpg","link":"https://3.cn/2ay1-e5t","name":"京东云","status":9,"txt":"京东云特惠专区","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":6,"img":"new_ads.png","link":"https://www.iodraw.com/ads","name":"发布广告","status":9,"txt":"发布广告","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":7,"img":"yun_910_50.png","link":"https://activity.huaweicloud.com/discount_area_v5/index.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=aXhpYW95YW5nOA===&utm_medium=cps&utm_campaign=201905","name":"底部","status":9,"txt":"高性能云服务器2折起","type":2,"updateTime":1735660800000,"userId":3}]
<>一、 题目要求
<>二、步骤
<>1.总体分析
输入两个正整数,第一个是“要打印出来的”,第二个是“个数”。
这样我们可以分两种情况:①当第二个输入的数字为1时,输出的结果就是n = n
②当大于1时,则需要循环,循环要求每次把上次循环的数*10再加上第一次输入的那个数即可。由于“+”比等号左边的个数少一个,所以打印最后一个数的时候,不同时打印“+”
<>2.框架:输入两个数(中间的实现略)最后打印
还需再创建一个变量t,用来存第一次输入的值(用于上面②中每次循环最后加上的内个数)
#include<stdio.h> int main() { int a, n,; int sum = 0; int t; scanf("%d%d", &a,
&n); t = a; if (n == 1) { printf("%d", t); } else//即n>1时 { //这里n>1时,要输出“+”
//并求出所有数相加,即“=”右边的值 sum } //最后输出“=***” printf("=%d",sum); return 0; }
<>3.n>1时 (else内部)
“=”左边总共有n个数相加,只有最后一个数最后直接输出这个数即可,对于前面的,输出每个数的时候要在其后面接上“+”
for (int i = 1; i < n; i++) { if (i == 1) { printf("%d+", a); } a = a * 10 + t;
//因为for里循环的次数的n-1 sum += a; if (i < n - 1) { printf("%d+", a); } else { printf(
"%d", a); } } sum = sum + t;
<>4.在最前面加上“判断输入的为整数”
if(a>0&&n>0)
<>5.最终代码
#include<stdio.h> int main() { int a, n,; int sum = 0; int t; scanf("%d%d", &a,
&n); t = a; if (a > 0 && n > 0) { if (n == 1) { printf("%d", t); } else for (int
i= 1; i < n; i++) { if (i == 1) { printf("%d+", a); } a = a * 10 + t; sum += a;
if (i < n - 1) { printf("%d+", a); } else { printf("%d", a); } } sum += t;
printf("=%d", sum); } return 0; }