实验二

1.getchar&putchar

 1 #include<stdio.h>
 2 #include<stdlib.h>
 3 int main()
 4 {
 5     char table1, table2, table3, table4, table5;
 6     table1 = getchar();
 7     table2 = getchar();
 8     table3 = getchar();
 9     table4 = getchar();
10     table5 = getchar();
11     putchar(table1);
12     putchar(table2);
13     putchar(table3);
14     putchar(table4);
15     putchar(table5);
16     system("pause");
17     return 0;
18 }

演示:

 

 

实验二

 

2.闰年判断:

 1 #include<stdio.h>
 2 #include<stdlib.h>
 3 int main()
 4 {
 5     int year, month, days;
 6     printf("input the year:");
 7     scanf_s("%d", &year);
 8     month = 2;
 9     if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0)
10     {
11         days = 29;
12     }
13     else
14     {
15         days = 28;
16     }
17     printf("year:%d ,month:%d,days:%d\n", year, month, days);
18     system("pause");
19     return 0;
20 }

 

演示:

输入2000

实验二

输入2018

 

实验二

 

3.判断三角形

 

 1 #include<stdio.h>
 2 #include<stdlib.h>
 3 int main()
 4 {
 5     int a, b, c;
 6     printf("input three numbers:\n");
 7     scanf_s("%d", &a);
 8     scanf_s("%d", &b);
 9     scanf_s("%d", &c);
10     if (a + b > c && a + c > b && b + c > a)
11     {
12         if (a == b || a == c || b == c)
13         {
14             if (a == b && b == c)
15             {
16                 printf("equilateral triangle\n");
17             }
18             else if (a * a + b * b == c * c || a * a + c * c == b * b || b * b + c * c == a * a)
19             {
20                 printf("isosceles  right triangle\n");
21             }
22             else
23             {
24                 printf("isosceles triangle\n");
25             }
26         }
27         else if(a * a + b * b == c * c || a * a + c * c == b * b || b * b + c * c == a * a)
28         {
29             printf("right triangle\n");
30         }
31         else
32         {
33             printf("ordinary triangle\n");
34         }
35     }
36     else
37     {
38         printf("unable to get a triangle\n");
39     }
40     system("pause");
41     return 0;
42 }

 

 

演示:

3,3,8(无法构成)

实验二

 

 

3,4,5(直角三角形)

 

实验二

 

 

6,6,6(等边三角形)

 

实验二

 

 

4.税率计算

 

 1 #include<stdio.h>
 2 #include<stdlib.h>
 3 int main()
 4 {    
 5     double a, rate, tax, profit;
 6     printf("input the date\na=");
 7     scanf_s("%lf", &a);
 8     if (0 <= a && a < 500)
 9     {
10         rate = 0;
11     }
12     else if (500 <= a && a < 1000)
13     {
14         rate = 0.05;
15     }
16     else if (1000 <= a && a < 2000)
17     {
18         rate = 0.08;
19     }
20     else if (2000 <= a && a < 5000)
21     {
22         rate = 0.10;
23     }
24     else if (5000 <= a)
25     {
26         rate = 0.15;
27     }
28     tax = a * rate;
29     profit = a - tax;
30     printf("a=%lf\nrate=%lf\ntax=%lf\nprofit=%lf\n", a, rate, tax, profit);
31     system("pause");
32     return 0;
33 }

 

演示:

 

a=280

 

实验二

 

 

a=512

 

实验二

 

 

a=1000

 

实验二

 

a=4250

 

实验二

 

 

a=5000

 

实验二

 

上一篇:[LeetCode] 976. Largest Perimeter Triangle (C++)


下一篇:Daliy Algorithm (动态规划,思维)-- day 77