for循环
#include <iostream>
using namespace std;
int main() {
//显示1,2,3...10
for (int i = 1; i <= 10; i++)
cout << i << endl;
//显示10,9,8...1
for (int i = 10; i>= 1; i--)
cout << i << endl;
//显示1,3,5...9
for (int j = 1; j <= 10; j += 2)
cout << j << endl;
//显示ABC...Z
for (char c = 'A'; c < 'Z'; c++)
cout << c << endl;
//显示0,0.1,0.2...1.0
for (float a = 0; a <= 1.1; a+=0.1)
cout << a << endl;
//计算s=1+2+3...+100
int s = 0;
for (int n = 1; n <= 100; n++)
s = s + n;
cout << "s="<<s << endl;
return 0;
}

浙公网安备 33010602011771号