zoukankan      html  css  js  c++  java
  • 实验二 选择结构程序设计

    (1)

    #include <stdio.h>
    
    int main()
    {
    	char a,b,c,d,e;
    	a = getchar();
    	b = getchar();
    	c = getchar();
    	d = getchar();
    	e = getchar();
    	putchar(a);
    	putchar(b);
    	putchar(c);
    	putchar(d);
    	putchar(e);
    	putchar("\n");
    	return 0;
    }
    

     

    (2)

    #include<stdio.h>
    
    int main()
    {
    	int year,month,days;
    	month = 2;
    	printf("input the year:");
    	scanf("%d",&year);
    	if((year % 4 == 0 && year % 100 != 0)|| year % 400 == 0 && year % 100 == 0)
    	{
    		days=29;
    		printf("year:");
    		printf("%d\n",year);
    		printf("month:");
    		printf("%d\n",month);
    		printf("days:");
    		printf("%d\n",days);
    	}
    	else{
    		days=28;
            printf("year:");
    		printf("%d\n",year);
    		printf("month:");
    		printf("%d\n",month);
    		printf("days:");
    		printf("%d\n",days);
    	}
    
    return 0;
    }
    

     

    (3)

    #include<stdio.h>
    #include<math.h>
    
    int main()
    {
    	int a,b,c;
    	scanf("%d%d%d",&a,&b,&c);
    	if((a+b)>c && (a+c)>b && (b+c)>a)
    	{
    		printf("能构成三角形\n");
    
    	    if((pow(a,2)+pow(b,2)==pow(c,2)) || (pow(a,2)+pow(c,2)==pow(b,2)) || (pow(b,2)+pow(c,2)==pow(a,2)))
    		{
    			printf("直角三角形\n");
    		}
    		if((a==b)||(a==c)||(b==c))
    		{
    			if((a==b)&&(a==c)&&(b==c))
    			{
    				printf("等边三角形\n");
    			}
    			else
    			{
    				printf("等腰三角形\n");
    			}
    		}
    	}
    	else
    	{
    		printf("不能构成三角形\n");
    	}
    
    return 0;
    }
    

     

    (4)

    #include<stdio.h>
    
    int main()
    {
    	double a,rate,tax,profit;
    	printf("input a:");
    	scanf("%lf",&a);
    	if(a<500)
    	{
    		rate = 0.00;
    		tax = a * rate;
    		profit = a - tax;
    	}
    	else if(a>=500 && a<1000)
    	{
    	    rate = 0.05;
    		tax = a * rate;
    		profit = a - tax;
    	}
    	else if(a>=1000 && a<2000)
    	{
    	    rate = 0.08;
    		tax = a * rate;
    		profit = a - tax;
    	}
    	else if(a>=2000 && a<5000)
    	{
    	    rate = 0.10;
    		tax = a * rate;
    		profit = a - tax;
    	}
    	else if(a>5000)
    	{
    	    rate = 0.15;
    		tax = a * rate;
    		profit = a - tax;
    	}
    
    	printf("%lf\n%lf\n%lf\n",rate,tax,profit);
    
    return 0;
    }
    #include<stdio.h>
    
    int main()
    {
    	int c;
    	double a,rate,tax,profit;
    	printf("please enter a:");
    	scanf("%lf",&a);
    	if(a>=5000) c=10;
    	else        c=a/500;
    	switch(c)
    	{
    	case 0: rate=0.00;break;
    	case 1: rate=0.05;break;
    	case 2: 
    	case 3: rate=0.08;break;
    	case 4:
    	case 5:
    	case 6:
    	case 7:
    	case 8:
    	case 9: rate=0.10;break;
    	case 10: rate=0.15;break;
    	}
    
    	tax = a * rate;
    	profit = a - tax;
    	printf("%lf\n%lf\n%lf\n",rate,tax,profit);
    
    return 0;
    }
    

     

  • 相关阅读:
    黑马程序员系列第十篇 异常
    黑马程序员系列第八篇 IO(2)
    黑马程序员系列第九篇 类加载器
    黑马程序员系列第六篇 面向对象基础
    黑马程序员系列第七篇 IO(1)
    黑马程序员系列第五篇 集合(2)
    黑马程序员系列第四篇 集合(1)
    黑马程序员系列第三篇 反射
    vue 自定义指令集合
    计算图片缩放比例 使图片不变形
  • 原文地址:https://www.cnblogs.com/P201821430044/p/10768757.html
Copyright © 2011-2022 走看看