4.6:
#include <iostream>
using namespace std;
int main()
{
cout << "请输入一个非负数: " << endl;
int a = 0;
cin >> a;
if (a % 2 == 0)
{
cout << "偶数" << endl;
}
else
{
cout << "奇数" << endl;
}
system("pause");
return 0;
}
4.10:
#include <iostream>
using namespace std;
int main()
{
cout << "请输入一个整数: " << endl;
int a = 0;
while (cin >> a)
{
if (a == 42)
{
cout << "输入正确" << endl;
break;
}
else
{
cout << "请再次输入: " << endl;
}
}
system("pause");
return 0;
}
4.21:
#include <iostream>
using namespace std;
#include<vector>
int main()
{
vector<int>v;
for (int i = 0; i &l