控制结构程序设计
if选择结构
// 分类讨论,不重不漏
#include <iostream>
using namespace std;
int main()
{
int x;
cin >> x;
if (x > 0) cout << '+' << '\n';
if (x > 0) cout << '+' << '\n';
else cout << "-" << '\n';
if (x > 0) cout << '+' << '\n';
else if (x == 0) cout << '0' << '\n';
else cout << '-' << '\n';
if (x > 0) cout << '+';
else{
if (x == 0) cout << '0';
else cout << '-';
}
//if嵌套,套一层而已
if (x >= 0){
if (x == 0) cout << '0' << '\n';
else cout << '+' << '\n';
}
return 0;
}
switch语句
我从来不用switch..,你们用不用随意吧
// 还是认真的给一个示例
#include <iostream>
using namespace std;
int main()
{
int n;
cin >> n;
switch(n){
case 1: cout << 1 << '\n'; break;
case 2: cout << 2 << '\n'; break;
default: cout << "不是1,也不是2" << '\n';
}
return 0;
}
一本通习题
//
//
//
//
//
//
//
//
//
//
//
//
//分段函数,属于超前背景知识
//
//
//数据水
//只需要判断两边之和
//能被4整除,不能被100整除的,是闰年
//能被400整除的,是闰年
//
//
//一元二次方程,属于超前背景知识