|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 这是她 于 2020-4-22 21:11 编辑
When everything seems to be going against you,remember that the airplane takes off against the wind,not with it.
循环来喽!!!!!!!!!!!
- #include <iostream>
- #include <string>
- using namespace std;
- int main()
- {
- int bus;//可以在外面先定义变量
- int track,trolley = 10,coach = 20;
- string station;
-
- for (int bus = 0; bus < 10; bus++)//看这里,也可以在for循环这里定义变量;当条件不满足第二个表达式的时候结束循环;更新用于测试的值。
- {
- cout << "Look" << endl;
- cout << "The quantity of bus is : " << bus << endl;
- }//对于for循环,如果是循环体是一条语句-->可以不使用大括号括起来;否则-->要用大括号将循环体括起来
- //花括号括起来的代码块将被视为一条语句
-
- int i = for (int a = 10; a < 0; a--)
- cout << a;//一定要注意一下不能把for循环赋值给变量
-
- cout << "Please enter the track : " << endl;
- cin >> track;
- for (int railway = 2; railway < 20 ; railway += track)
- cout << railway << endl;//track是步长,按照步长来进行循环计数的增减
-
- cout << "Enter a station :";
- cin >> station;
-
- for (int b = station.size()-1;b >= 0;b--)//使用for循环访问字符串
- cout << station[b];
- cout << "\nBye.\n";
-
- int taxi[4][5] =
- {
- {45,75,22,75,84},
- {36,63,26,17,72},
- {37,83,85,13,75},
- {53,35,77,56,67}
- };//初始化二维数组:使用逗号分隔的一维数组初始化用花括号括起来组成
-
- for(int x=0;x < 4;x++)
- {
- for(int y = 0;y < 5;y++)
- cout << taxi[x][y] << "\t";
- cout << endl;
- }//使用嵌套循环-->就是在一个循环里在装上一个循环
-
- while(trolley > 5)//while循环:若表达式为0或false时,跳出循环 ——先判断在执行
- {
- cout << "The quantity of trolley is : " << trolley << endl;
- trolley -= 1;
- }
-
- do//先执行循环体,在判断表达式是否满足条件;false——>循环中止
- {
- cout << coach << endl;
- coach += 2;
- }while(coach < 32);
-
- return 0;
- }
复制代码
渣渣一个 ,大佬们手下留情
留个建议,消除霉运
|
|