#include <iostream>
using namespace std;
int main (void)
{
int x;
cin >> x;
cout << "if-else: ";
if (x == 0) {
cout << "0" << endl;
} else if (x == 1) {
cout << "1" << endl;
} else if (x == 2) {
cout << "2" << endl;
} else {
cout << "not 0, 1, 2" << endl;
}
cout << "switch: ";
switch (x)
{
case 0:
cout << "0" << endl;
break;
case 1:
cout << "1" << endl;
break;
case 2:
cout << "2" << endl;
break;
default:
cout << "not 0, 1, 2" << endl;
break;
}
return 0;
}
, case , break , , . .. break . , , goto.
, default, , . , . {} .
2.2.
, . ++ : for, while do while.
, , , , .. . : .
, break, continue.
, break continue . . , .
2.2.1. for
for. for .
2.4. 0 9.
#include <iostream>
using namespace std;
int main (void)
{
for (int i = 0; i < 10; i++)
cout << i*i << " ";
|
|
return 0;
}
, , , , . , . for . . , , , bool. , . , . .
2.5. .
#include <iostream>
using namespace std;
int main (void)
{
unsigned int x;
int y, z;
cin >> y >> x;
for (z = 1; x > 0; x--)
z *= y;
cout << z << endl;
return 0;
}
for , .