[{"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}]
您可能感兴趣的话题:
C++
核心提示:本教程为大家介绍C++语言中的for 循环语句。
for 循环
有时候需要处理的是反复进行的工作,这时候使用循环语句是很好的方法,下面我们来看一个练习;
1)点菜单“应用程序-编程-Geany”启动 Geany ,新建一个 c++ 源程序;
2)点菜单“文件-另存为”命令,以“for”为文件名,保存文件到自己的文件夹;
2、输入程序代码
1)先来看一个显示 10 以内的整数代码;
for (int i=0; i<10; i++)
{
cout << i << " ";
}
2)for 语句括号里有三句,第一句是定义一个循环变量,赋初值为 0,中间一句是循环条件,i 小于 10
的时候,就执行循环语句,这儿是下面的内容,需要用大括号括起来,
后面一句是步长,i++ 是 i=i+1,加一增量操作;
3)保存、编译、生成、运行,显示出 0-9 十个数;
4)因为 i 是从 0 开始的,并且必须小于10,等于也不行,所以是两头是 0 和 9;
5)好的,继续输入一个累加程序,从 1 加到 100(1 + 2 + 3 + ... + 100);
int sum = 0;
for (int i=1; i<=100; i++)
{
sum = sum + i;
}
cout << "sum=" << sum;
6)这次 i<=100,可以加到100,sum 是存放和的变量,每次往里面加一个 i,
sum = sum + i ,这一句是累加,像叠木箱一样;
7)保存、译、生成、运行,最终显示出累加的结果;
#include
using namespace std;
int main(int argc, char** argv)
{
for (int i=0; i<10; i++)
{
cout << i << " ";
}
cout << endl;
int sum = 0;
for (int i=1; i<=100; i++)
{
sum = sum + i;
}
cout < < "sum=" << sum;
return 0;
}