编写一个 C++ 程序,使用 for 循环打印前 10 个奇数自然数。
#include<iostream>
using namespace std;
int main()
{
cout << "The First 10 Odd Natural Numbers are\n";
for (int i = 1; i <= 10; i++)
{
cout << 2 * i - 1 << "\n";
}
}

C++ 程序使用 while 循环打印前 10 个奇数自然数
#include<iostream>
using namespace std;
int main()
{
int i = 1;
cout << "The First 10 Odd Natural Numbers are\n";
while (i <= 10)
{
cout << 2 * i - 1 << "\n";
i++;
}
}
The First 10 Odd Natural Numbers are
1
3
5
7
9
11
13
15
17
19
此 C++ 程序 使用 do while 循环并显示前 10 个奇数自然数。
#include<iostream>
using namespace std;
int main()
{
int i = 1;
cout << "The First 10 Odd Natural Numbers are\n";
do
{
cout << 2 * i - 1 << "\n";
} while (++i <= 10);
}
The First 10 Odd Natural Numbers are
1
3
5
7
9
11
13
15
17
19