1 ////控制结构:有选择性的执行某部分代码-数据结构+算法=程序
2 //if(){
3 //
4 //}
5 //else{
6 //
7 //}
8 ////如果满足就输出YES,否则输出NO
9 //if(a == 1){
10 //
11 //}
12 //else if(a == 2){
13 //
14 //}else if(a == 3){
15 //
16 //}else{
17 //
18 //}
19 //
20
21 #include <iostream>
22 using namespace std;
23 //偶数判断 :判断一个数是否是偶数,若是输出yes。
24 int main(){
25 int a;
26 cin >> a;
27 if(a % 2 == 0){
28 cout << "yes" << endl;
29 }
30 return 0;
31 }
1 #include <iostream>
2 using namespace std;
3 //判断数的范围 - 判断一个数是否在1-100之间,若是输出yes
4 //任务:2位数中,所有能被7整除的数有多少个。
5 int main(){
6 int a;
7 cin >> a;
8 if(a > 1 && a < 100){
9 cout << "yes" << endl;
10 }
11 return 0;
12 }
1 #include <iostream>
2 using namespace std;
3 //输入:8 题目:输入n个整数,输入一个比较数b,统计n个数中与b相同的数的总个数。
4 //输入: 1 3 6 9 1 2 3 8
5 //输入: 1
6 //输出:2
7 int main(){
8 int n,b,c;
9 cin >> n;
10 int a[n];
11 for(int i = 0;i < n;i++){
12 cin >> a[i];
13 }
14 cin >> b;
15 for(int j = 0;j < n;j++){
16 if(b == a[j]){
17 c++;
18 }
19 }
20 cout << c << endl;
21 return 0;
22 }
1 #include <iostream>
2 using namespace std;
3 //条件:7月1日是周一。
4 //小明同学非常想去看演唱会。但是小明周二、四、六有课。
5 //某一个歌星,在7月时每逢6的倍数号晚会召开演唱会。
6 //请问小明周7月的哪几天可以参加演唱会?
7 int main(){
8 // 1 2 3 4 5 6 7
9 // 8 9 10 11 12 13 14
10 // 15 16 17 18 19 20 21
11 // 22 23 24 25 26 27 28
12 // 29 30 31
13 int a[31] = {2,9,16,23,30,4,11,18,25,6,13,20,27};
14 int b[31];// 6 12 18 24 30
15 int c[31];
16 for(int i = 1;i <= 31;i++){
17 if(i % 6 == 0){
18 b[i - 1] = i;
19 }
20 }
21 for(int i = 0;i < sizeof(a)/sizeof(a[1]);i++){
22 for(int j = 0;j < sizeof(b)/sizeof(b[1]);j++){
23 if(a[i] != b[j]){
24 c[j] = b[j];
25 }
26 }
27 }
28 for(int i = 0;i < sizeof(c)/sizeof(c[1]);i++){
29 cout << c[i] << " ";
30 }
31 return 0;
32 }
1 #include <iostream>
2 using namespace std;
3 //n! 求n的阶乘。 n! = n * (n-1)*(n-2)*....*3*2*1
4 int main(){
5 //n! 阶乘
6 // 4! = 4 * 3 * 2 * 1
7 int n,sum = 1;
8 cin >> n;
9 for(int i = n;i >= 1;i--){
10 //从i到1的值相乘
11 sum *= i;
12 }
13 cout << sum << endl;
14 return 0;
15 }
1 #include <iostream>
2 using namespace std;
3 // 已知等式sum = 1 + 2 + 3 +...+ n,要求输入一个数a,求使得sum > a的最小n是多少?
4 int main(){
5 int a;
6 cin >> a;
7 int sum = 0,i = 1;
8 bool n = true;
9 do{
10 i++;
11 sum += i;
12 if(sum >= a){
13 cout << i << endl;
14 n = false;
15 }
16 }while(n);
17 return 0;
18 }
1 #include <iostream>
2 using namespace std;
3 //两位数中能够被7整除的数总和
4 int main(){
5
6 return 0;
7 }
1 #include <iostream>
2 using namespace std;
3 //计算邮资:未满1000克的快递基础费是8元,超过1000克的部分每500克收取4元(不满500按500算),加急费5元,求最后的邮费是多少(保留两位小数)?
4 int main(){
5 double a,money = 0,money1 = 0,money2 = 0,c = 0;
6 char y;
7 cin >> a >> y;
8 if(a <= 1000){
9 money1 = 8;
10 }else{
11 c = (a - 1000)/500;
12 if(c < 1 && c > 0){
13 money2 = 4 + 8;
14 }
15 if(c > 1){
16 money2 = int(c) * 4 + 8 + 4;
17 }
18 }
19 money = money1 + money2;
20 if(y == ‘y‘){
21 money = money + 5;
22 }
23 printf("%.2lf",money);
24 return 0;
25 }

1 #include <iostream>
2 using namespace std;
3 //判断闰年 1
4 int main(){
5 int year;
6 //方法一
7 // while(cin >> year){
8 // //1.能被400整除的年份一定是闰年 year % 400 == 0
9 // //2.能够被4整除且不能被100整除 year % 4 == 0 && year % 100 != 0
10 // if((year % 400 == 0) || (year % 4 == 0 && year % 100 != 0)){
11 // cout << "闰年" << endl;
12 // }else{
13 // cout << "平年" << endl;
14 // }
15 // }
16
17 //方法二
18 while(cin >> year){
19 if(year % 400 == 0){
20 cout << "闰年" << endl;
21 }else{
22 if(year % 4 == 0 && year % 100 != 0){
23 cout << "闰年" << endl;
24 }else{
25 cout << "平年" << endl;
26 }
27 }
28 }
29 return 0;
30 }
1 #include <iostream>
2 using namespace std;
3 //四则运算器
4 int main(){
5 float num1,num2,c = 0;
6 char op;
7 cin >> num1 >> num2 >> op;
8 switch(op){
9 case ‘+‘:
10 c = num1 + num2;
11 break;
12 case ‘-‘:
13 c = num1 - num2;
14 break;
15 case ‘*‘:
16 c = num1 * num2;
17 break;
18 case ‘/‘:
19 c = num1 / num2;
20 break;
21 default:
22 cout << "输入的不是有效的运算符";
23 }
24 printf("%.4f",c);
25 return 0;
26 }
1 #include <iostream>
2 using namespace std;
3 //三目运算
4 int main(){
5 int a;
6 cin >> a;
7 if(a > 100){
8 cout << "yes" << endl;
9 }else{
10 cout << "no" << endl;
11 }
12 //三目运算用法
13 string c = (a % 3 == 0) && (a % 5 == 0) ? "yes":"no";
14 cout << c << endl;
15
16 return 0;
17 }
1 #include <iostream>
2 using namespace std;
3 //个人所得税:超过3500元上税5%;超过5500元,上税10%;
4 //超过12000元,上税15%;
5 //当工资收入不超过15000的时候,所缴个人所得税为多少?
6 int main(){
7 double a,y = 0;
8 scanf("%lf",&a);
9 if(a > 3500 && a <= 5500){
10 y = (a - 3500) * 0.05;
11 }else if(a > 5500 && a <= 12000){
12 y = (a - 5500)*0.1 + 2000 * 0.05;
13 }else if(a > 12000 && a <= 15000){
14 y = (a - 12000) * 0.15 + 6500*0.1 + 2000*0.05;
15 }
16 printf("%.5lf",y);
17 return 0;
18 }
1 #include <iostream>
2 using namespace std;
3 //从大到小顺序输出三个数
4 int main(){
5 int a,b,c,temp;
6 cin >> a >> b >> c;
7 if(a < b){
8 temp = a;
9 a = b;
10 b = temp;
11 }
12 // 19 22 33 --->22 19 33
13 if(a < c){
14 temp = a;
15 a = c;
16 c = temp;
17 }
18 if(b < c){
19 temp = b;
20 b = c;
21 c = temp;
22 }
23 cout << a << " " << b << " " << c << endl;
24 return 0;
25 }
1 #include <iostream>
2 using namespace std;
3 //任务:2位数中,所有能被7整除的数有多少个。
4 int main(){
5 //10-99
6 int c = 0;
7 for(int i = 10;i < 100;i++){
8 if(i % 7 == 0){
9 c++;
10 }
11 }
12 cout << c << endl;
13 return 0;
14 }
1 #include <iostream>
2 using namespace std;
3 // 最大公约数
4 int main(){
5 int m,n,gcd;
6 cin >> m >> n;
7 gcd = m > n ? n : m;//找到小的那个数
8 while(gcd > 1 && (m % gcd != 0 || n % gcd != 0)){
9 gcd--;
10 }
11 cout << gcd << endl;
12 return 0;
13 }
1 #include <iostream>
2 using namespace std;
3 // 满足条件的最小值n:已知s = 1 + 1/2 + 1/3 +...+1/n;求满足s < 5的最小值n;
4 int main(){
5 int i = 0;
6 float s = 0;
7 while(s < 5){
8 ++i;
9 s += 1.0/i;
10 }
11 cout << i;
12 return 0;
13 }
1 #include <iostream>
2 using namespace std;
3 // 弹跳球高度计算:一个球从h的高度下落,每次下落后弹起的高度为原来的一半。求:到第十次总共经过的高度是多少?第十次弹起的高度是多少?
4 int main(){
5 double h,sum = 0;
6 int n = 1;
7 cin >> h;
8 sum = h;
9 do{
10 h = h * 0.5;
11 sum = sum + 2*h;
12 n++;
13 }while(n <= 9);
14 cout << sum << endl;
15 cout << h << endl;
16 return 0;
17 }
1 #include <iostream>
2 using namespace std;
3 // 角谷猜想-任意一个正整数,当他不为1时,如果是一个偶数则除与2,若是奇数,则乘以3加上1,最终该数都会变成1.请输出该整数的变化过程,若该数为1另起一行输出"End"。例:输入:5 输出:16 8 4 2 1.
4 int main(){
5 int n;
6 cin >> n;
7 while(n != 1){
8 if(n % 2 == 0){
9 n = n * 0.5;
10 }else{
11 n = n * 3 + 1;
12 }
13 cout << n << " ";
14 cout << endl;
15 }
16 if(n == 1){
17 cout << "End" << endl;
18 }
19 return 0;
20 }
1 #include <iostream>
2 using namespace std;
3 // 级数求和-已知:Sn=1 + 1/2 + 1/3 +..+1/n;显然对于任意一个整数K,当n足够大时,Sn>K。现给出一个整数K(1 <= k <= 15),要求计算出一个最小的n,使得Sn>K。
4 int main(){
5 int n = 1,k;
6 cin >> k;
7 float sn = 0;
8 while(sn <= k){
9 ++n;
10 sn += 1.0/n;
11 }
12 cout << n;
13 return 0;
14 }
原文:https://www.cnblogs.com/huihuilaoshi/p/11196208.html