C 语⾔:菜鸟教程经典100例题(1-50)
注:以下答案与原⽂不完全相同
实例1
有1、2、3、4个数字,能组成多少个互不相同且⽆重复数字的三位数?都是多少?实例2
#include <stdio.h>int main (void ){ int i , j , k ; int 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 ) { printf ("%d%d%d\n", i , j , k ); n ++; } } } } printf ("count:%d\n", n ); return 0;}/*123124132134142143213214231234241243312314321324341342412413421423431432count:24*/
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
企业发放的奖⾦根据利润提成。
利润(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,求应发放奖⾦总数?
#include <stdio.h>#define r1 0.1#define r2 0.075#define r3 0.05#define r4 0.03#define r5 0.015#define r6 0.01int main (void ){ double l ; double bonus ; printf ("Please enter monthly profit:\n"); scanf ("%lf", &l ); do { if (l <= 10) bonus = l * r1; else if (l > 10 && l <= 20) bonus = 10 * r1 + (l - 10) * r2; else if (l > 20 && l <= 40) bonus = 10 * r1 + 10 * r2 + (l - 20) * r3; else if (l >= 40 && l < 60) bonus = 10 * r1 + 10 * r2 + 20 * r3 + (l - 40) * r4; else if (l >= 60 && l < 100) bonus = 10 * r1 + 10 * r2 + 20 * r3 + 20 * r4 + (l - 60) * r5; else bonus = 10 * r1 + 10 * r2 + 20 * r3 + 20 * r4 + 40 * r5 + (l - 100) * r5; printf ("Your bonus is %lf\n", bonus ); printf ("Please enter monthly profit:\n"); scanf ("%lf", &l ); } while (l > 0); printf ("Done.\n"); return 0;}/*Please enter monthly profit:12Your bonus is 1.150000Please enter monthly profit:22Your bonus is 1.850000Please enter monthly profit:52Your bonus is 3.110000Please enter monthly profit:82Your bonus is 3.680000Please enter monthly profit:102Your bonus is 3.980000Please enter monthly profit:0Done.*/
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
菜鸟教程python面向对象17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
实例3
⼀个整数,它加上100后是⼀个完全平⽅数,再加上168⼜是⼀个完全平⽅数,请问该数是多少?实例4
输⼊某年某⽉某⽇,判断这⼀天是这⼀年的第⼏天?#include <stdio.h>/*i + 100 = n²i + 100 + 168 = m²m² - n² = 168 = (m + n)(m - n)13 * 13 = 169m >= 13n >= 1m + n 为偶数m - n 为偶数m - n >= 2m + n <= 84*/int main (void ){ int i ; for (int m = 13; m < 84; m ++) { for (int n = 1; n < 84; n ++) { if (m * m - n * n == 168) { i = n * n - 100; printf ("i = %d\n", i ); } } } return 0;}/*i = -99i = 21i = 261i = 1581*/
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39#include <stdio.h>/*#include <stdio.h>int main(void){ int y; printf("请输⼊年份,回车结束\n"); scanf("%d",&y); if((y % 4== 0 && y % 100 != 0) || ( y % 400 == 0 && y % 3200 != 0)|| y % 172800 == 0) printf("%d 是闰年\n",y); else printf("%d 是平年\n",y); return 0;1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
int main (void ){ int year , month , day , sum ; int leap = 0; int D [12] = { 31,28,31,30,31,30,31,31,30,31,30,31 }; printf ("Please enter date:(eg:1997 12 26)\n"); scanf ("%d %d %d", &year , &month , &day ); while (year > 0) { switch (month ) { case 1: sum = 0; break ; case
2: sum = D [1]; break ; case 3: sum = D [1] + D [2]; break ; case 4: sum = D [1] + D [2] + D [3]; break ; case 5: sum = D [1] + D [2] + D [3] + D [4]; break ; case 6: sum = D [1] + D [2] + D [3] + D [4] + D [5]; break ; case 7: sum = D [1] + D [2] + D [3] + D [4] + D [5] + D [6]; break ; case 8: sum = D [1] + D [2] + D [3] + D [4] + D [5] + D [6] + D [7]; break ; case 9: sum = D [1] + D [2] + D [3] + D [4] + D [5] + D [6] + D [7] + D [8]; break ; case 10: sum = D [1] + D [2] + D [3] + D [4] + D [5] + D [6] + D [7] + D [8] + D [9]; break ; case 11: sum = D [1] + D [2] + D [3] + D [4] + D [5] + D [6] + D [7] + D [8] + D [9] + D [10]; break ; case 12: sum = D [1] + D [2] + D [3] + D [4] + D [5] + D [6] + D [7] + D [8] + D [9] + D [10] + D [11]; break ; } if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0 && year % 3200 != 0) || year % 172800 == 0) { printf ("%d is leap\n", year ); leap = 1; } else printf ("%d is not leap\n", year ); if (leap == 1 && month > 2) sum = sum + 1;17181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论