虎为百兽尊,罔敢触其怒。 大明风华 朱棣因虎诗感动流泪 有 1 、 2 、 3 、 4 个数字,能组成多少个互不相同且无重复数字的三位数?都是多少? 实现思路: 打印: 企业发放的奖金根据利润提成。利润 (I) 低于或等于 10 万元时,奖金可提 10% ;利润高于 10 万元,低于 20 万元时,低于 10 万元的部分按 10% 提成,高于 10 万元的部分,可可提成 7.5% ; 20 万到 40 万之间时,高于 20 万元的部分,可提成 5% ; 40 万到 60 万之间时高于 40 万元的部分,可提成 3% ; 60 万到 100 万之间时,高于 60 万元的部分,可提成 1.5% ,高于 100 万元时,超过 100 万元的部分按 1% 提成,从键盘输入当月利润 I ,求应发放奖金总数? 实现思路: 方式一——if语句: 打印: 方式二——switch语句: 效果与方式一相同。 一个整数,它加上 100 后是一个完全平方数,再加上 168 又是一个完全平方数,请问该数是多少? 实现思路: 打印: 方式二: 打印: 显然,此时比方式一多了一个数-99,只要在方式一中i的初始值减小为-100即可。 输入某年某月某日,判断这一天是这一年的第几天? 实现思路: 打印: 输入三个整数 x、y、z ,请把这三个数由小到大输出。 实现思路: 打印:
惟有父子情,一步一回顾。习题1
显然,这个题目需要用到循环,并且是循环嵌套,先列出所有可能的组合,再去掉重复的组合即可。
代码如下:#include <stdio.h> int main(){ int i, j, k, n = 0; for(i = 1; i < 5; i++){ for(j = 1; j < 5; j++){ for(k = 1; k < 5; k++){ if(i != j && i != k && j != k){ n++; printf("%d%d%d", i, j, k); if(n % 5){ printf(" "); } else{ printf("n"); } } } } } printf("nnThere are %d numbers.n", n); return 0; }
123 124 132 134 142 143 213 214 231 234 241 243 312 314 321 324 341 342 412 413 421 423 431 432 There are 24 numbers.
习题2
该题需要用到if条件判断或switch语句。#include <stdio.h> int main(){ long profit, bonus; float ratio; printf("Please input the profit:"); scanf("%ld", &profit); if(profit > 0 && profit <= 100000){ bonus = profit * 0.1; } else if(profit > 100000 && profit < 200000){ bonus = 100000 * 0.1 + (profit - 100000) * 0.075; } else if(profit >= 200000 && profit < 400000){ bonus = 100000 * 0.1 + 100000 * 0.075 + (profit - 200000) * 0.05; } else if(profit >= 400000 && profit < 600000){ bonus = 100000 * 0.1 + 100000 * 0.075 + 200000 * 0.05 + (profit - 400000) * 0.03; } else if(profit >= 600000 && profit < 1000000){ bonus = 100000 * 0.1 + 100000 * 0.075 + 200000 * 0.05 + 200000 * 0.03 + (profit - 600000) * 0.015; } else{ bonus = 100000 * 0.1 + 100000 * 0.075 + 200000 * 0.05 + 200000 * 0.03 + 400000 * 0.015 + (profit - 1000000) * 0.01; }; printf("The bonus is %ld", bonus); return 0; }
Please input the profit:1234567 The bonus is 41845
#include <stdio.h> int main(){ long profit, bonus = 0; printf("Please input the profit:"); scanf("%ld", &profit); int pr = profit / 100000; if(pr > 10){ pr = 10; } switch(pr){ case 0: bonus = profit * 0.1;break; case 1: bonus = 100000 * 0.1 + (profit - 100000) * 0.075;break; case 2: case 3: bonus = 100000 * 0.1 + 100000 * 0.075 + (profit - 200000) * 0.05;break; case 4: case 5: bonus = 100000 * 0.1 + 100000 * 0.075 + 200000 * 0.05 + (profit - 400000) * 0.03; case 6: case 7: case 8: case 9: bonus = 100000 * 0.1 + 100000 * 0.075 + 200000 * 0.05 + 200000 * 0.03 + (profit - 600000) * 0.015;break; case 10: bonus = 100000 * 0.1 + 100000 * 0.075 + 200000 * 0.05 + 200000 * 0.03 + 400000 * 0.015 + (profit - 1000000) * 0.01;break; default: printf("Input Error!!n");break; } printf("The bonus is %ld", bonus); return 0; }
习题3
方式一——使用简单循环:#include <stdio.h> #include <math.h> int main(){ int i; for(i = 0; i <= 100000; i++){ int root1 = sqrt(i + 100), root2 = sqrt(i + 268); if(pow(root1, 2) == (i + 100) && pow(root2, 2) == (i + 268)){ printf("%8d", i); } } printf("n"); return 0; }
21 261 1581
假设该数为 x。
#include <stdio.h> int main (void) { int i, j, n, x; for (i = 1; i < 168 / 2 + 1; i++){ if (168 % i == 0){ j = 168 / i; if ( i > j && (i + j) % 2 == 0 && (i - j) % 2 == 0){ n = (i - j) / 2; x = n * n - 100; printf ("%8d", x); } } } printf("n"); return 0; }
-99 21 261 1581
习题4
假设月份为n,则天数为前n-1个月的天数加第n月的天数,如果n大于3时,要考虑是否为闰年,如果为闰年,则2月还要多加1天。#include <stdio.h> int main (void) { int year, month, day, days, leap = 0; printf("Please input the date(YYYY_MM-DD):"); scanf("%d-%d-%d", &year, &month, &day); switch(month){ case 1: days = 0;break; case 2: days = 31;break; case 3: days = 59;break; case 4: days = 90;break; case 5: days = 120;break; case 6: days = 151;break; case 7: days = 181;break; case 8: days = 212;break; case 9: days = 243;break; case 10: days = 273;break; case 11: days = 304;break; case 12: days = 334;break; default: printf("Input Error");break; } days += day; if(year % 4 ==0 && year % 100 != 0 || year % 400 == 0){ leap = 1; } if(leap && month > 2){ days += 1; } printf("Days = %dn", days); return 0; }
Please input the date(YYYY_MM-DD):2020-05-26 Days = 147
习题5
通过两两比较找出三者中最大和最小的数。#include <stdio.h> int main (void) { int x, y, z, temp; printf("Please input 3 numbers:n"); scanf("%d %d %d", &x, &y, &z); if(x > y){ temp = x; x = y; y = temp; } if(x > z){ temp = x; x = z; z = temp; } if(y > z){ temp = y; y = z; z = temp; } printf("Small to big: %d %d %d", x, y, z); return 0; }
Please input 3 numbers: 12 34 23 Small to big: 12 23 34
本网页所有视频内容由 imoviebox边看边下-网页视频下载, iurlBox网页地址收藏管理器 下载并得到。
ImovieBox网页视频下载器 下载地址: ImovieBox网页视频下载器-最新版本下载
本文章由: imapbox邮箱云存储,邮箱网盘,ImageBox 图片批量下载器,网页图片批量下载专家,网页图片批量下载器,获取到文章图片,imoviebox网页视频批量下载器,下载视频内容,为您提供.
阅读和此文章类似的: 全球云计算