C语言水题(DevForge学编程社区)

时间:2019-09-17
本文章向大家介绍C语言水题(DevForge学编程社区),主要包括C语言水题(DevForge学编程社区)使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

1、计算A+B

1 #include <stdio.h>
2 int main()
3 {
4     int a,b;
5     scanf("%d%d",&a,&b);
6     printf("%d",a+b);
7     return 0;
8 }

2、圆及圆球的相关计算

 1 #include <stdio.h>
 2 #include <math.h>
 3 #define PI 3.1415926
 4 int main()
 5 {
 6     double r,h,l,s,sq,vq,vz;
 7     scanf("%lf%lf",&r,&h);
 8     
 9     l = 2*PI*r;
10     s = PI*r*r;
11     sq = 4*s;
12     vq = PI*r*r*r*4/3;
13     vz = s*h;
14     
15     printf("%.2f\n",l);
16     printf("%.2f\n",s);
17     printf("%.2f\n",sq);
18     printf("%.2f\n",vq);
19     printf("%.2f\n",vz);
20     return 0;
21 }

3、计算成绩

#include <stdio.h>
int main()
{
    double a,b,c;
    scanf("%lf%lf%lf",&a,&b,&c);
    printf("%f\n",a+b+c);
    printf("%f",(a+b+c)/3);
    return 0;
}

4、找最大数

1 #include <stdio.h>
2 int main()
3 {
4     int a,b,c;
5     scanf("%d%d%d",&a,&b,&c);
6     int t = a>b?a:b;
7     printf("%d",t>c?t:c);
8     return 0;
9 }

5、找幸运数

#include <stdio.h>
int main()
{
    int n,t,t1 = 0;
    scanf("%d",&n);
    t = n;
    while(t)
    {
        t1 = t1*10+t%10;
        t /= 10;
    }
    if(n==t1)
        printf("yes");
    else
        printf("no");
    return 0;
}

6、奖金发放

 1 #include <stdio.h>
 2 #include <stdlib.h>
 3  
 4 int main()
 5 {
 6     double profits,bonus;
 7     scanf("%lf",&profits);
 8     double bonus1,bonus2,bonus3,bonus4,bonus5;
 9  
10     bonus1 = 10*0.1;
11     bonus2 = bonus1 + (20-10)*0.075;
12     bonus3 = bonus2 + (40-20)*0.05;
13     bonus4 = bonus3 + (60-40)*0.03;
14     bonus5 = bonus4 + (100-60)*0.015;
15      
16     if(profits<=10){
17         bonus = profits*0.1;
18     }
19     else if(profits<=20){
20         bonus = bonus1 + (profits-10)*0.075;
21     }
22     else if(profits<=40){
23         bonus = bonus2 + (profits-20)*0.05;
24     }
25     else if(profits<=60){
26         bonus = bonus3 + (profits-40)*0.03;
27     }
28     else if(profits<=100){
29         bonus = bonus4 + (profits-60)*0.015;
30     }
31     else{
32         bonus = bonus5 + (profits-100)*0.01;
33     }
34  
35  
36     printf("%f\n",bonus);
37  
38     return 0;
39 }

7、出租车费

 1 #include <stdio.h>
 2 #include <math.h>
 3 int main()
 4 {
 5    /*  */
 6     double distance,fee;
 7 
 8     scanf("%lf",&distance);
 9 
10     int d = distance;
11     if(d<=2){
12         fee = 7;
13     }
14     else if(d>2&&d<=15){
15         fee = 7 + ceil(distance-2)*1.5;
16     }
17     else if(d>15){
18         fee = 7 + (15-2)*1.5 + ceil(distance-15)*2.1;
19     }
20 
21     printf("%f\n" ,fee); 
22     
23     return 0;
24 }

8、是该年的第几天

 1 #include <stdio.h>
 2 int leap(int year);
 3 int days(int year,int month,int day);
 4 int main()
 5 {
 6     int year,month,day;
 7     scanf("%d-%d-%d",&year,&month,&day);
 8     printf("%d",days(year,month,day));
 9     return 0;
10 }
11 int leap(int year)
12 {
13    return (year%400==0||(year%4==0 && year%100!=0));
14 }
15 int days(int year,int month,int day)
16 {        
17     int days[] = {0,31,28,31,30,31,30,31,31,30,31,30,31};
18     int d=0;
19     for(int i=1; i<month; ++i)
20         d += days[i];
21     if(leap(year)&&month>2)
22         d++;        
23     return d + day;
24 }

9、成绩转换

 1 #include <stdio.h>
 2 
 3 int main()
 4 {
 5     int achievment;
 6     char ch;
 7     scanf("%d",&achievment);
 8     switch(achievment/10)
 9     {
10         case 10:
11         case 9: ch = 'A';break;
12         case 8: ch = 'B';break;
13         case 7: ch = 'C';break;
14         case 6: ch = 'D';break;
15         default: ch = 'E';        
16     }
17     printf("%c",ch);
18     return 0;
19 }

10、求建筑高度

 1 #include <stdio.h>
 2 #include <math.h>
 3 int main()
 4 {
 5     int h;
 6     float x,y,a,b,c,d;
 7     scanf("%f,%f",&x,&y);
 8     a=sqrt((x-2)*(x-2)+(y-2)*(y-2)); //点到圆心的距离
 9     b=sqrt((x+2)*(x+2)+(y-2)*(y-2));
10     c=sqrt((x+2)*(x+2)+(y+2)*(y+2));
11     d=sqrt((x-2)*(x-2)+(y+2)*(y+2));
12     if(a<=1||b<=1||c<=1||d<=1)
13         h=10;
14     else
15         h=0;
16     printf("%d\n",h);
17     return 0;
18 }

 

$flag 上一页 下一页