@【TOC】选择结构程序设计

#include <stdio.h>
int main ( )
{
   float f,c; 
   f=64.0; 
   c=(5.0/9)*(f-32); 
   printf("f=%f\nc=%f\n",f,c);        
   return 0;
 }

在这里插入图片描述

#include <stdio.h>
int main ( ) 
{  int x; 
    scanf("%d",&x);
    if (x>=0) 
       printf("%d\n",x);
    else  
       printf("%d\n",-x);
    return 0;
}

在这里插入图片描述

#include <stdio.h>
int main ( ) 
{  int x; 
    scanf("%d",&x);
    if (x<0) 
        x=-x;
    printf("%d\n",x);
}

在这里插入图片描述

#include <stdio.h>
int main()
{ float a,b,t;
   scanf("%f,%f",&a,&b);
   if(a>b)
    {  t=a;
        a=b;
        b=t;
     }
   printf("%5.2f,%5.2f\n",a,b);
   return 0;
}

在这里插入图片描述

#include <stdio.h>
int main()
{ float a,b,c,t;
   scanf("%f,%f,%f",&a,&b,&c);
   if(a>b)
   {   t=a;  a=b;  b=t;   } 
   if(a>c)
   {   t=a;  a=c;  c=t;   }        
   if(b>c) 
   {   t=b;  b=c;  c=t;   }                        
   printf("%5.2f,%5.2f,%5.2f\n",a,b,c);  
   return 0;
}

在这里插入图片描述

#include <stdio.h>
#include  <math.h>
int main ( ) 
 {
	int a=3,b=4,c=5,x=6,y=7; 
    printf("%d\n",a+b>c&&b==c);  
    printf("%d\n",a||b+c&&b-c);     
	printf("%d\n",!(a>b)&&!c||1);
	printf("%d,%d,%d\n",!(x=a)&&(y=b)&&0,x,y);    
	printf("%d\n",!(a+b)+c-1&&b+c/2);        
    return 0;
}

在这里插入图片描述

#include <stdio.h>
int main ( ) 
{int a,b,c,max;
  scanf("%d,%d,%d",&a,&b,&c);
  if(a>=b && a>=c)
    max=a;
  if(b>=a && b>=c)
    max=b;
  if(c>=a && c>=a)
    max=c;
  printf("%d",max);        
  return 0;
}

在这里插入图片描述

#include <stdio.h>
int main ( ) 
{char c;
  scanf("%c",&c);
  if((c>='A' && c<='V') || (c>='a' && c<='v') )
     c=c+4;
  else
     c=c-22;  
  printf("%c",c);        
  return 0;
}

在这里插入图片描述

#include <stdio.h>
int main()
{  float p,w,s,d,f;
   printf("please enter price,weight,discount:");      
   scanf("%f,%f,%f",&p,&w,&s);        
   
   if(s<250)  d=0;                                 
   else  if(s<500)  d=2;                                  
            else  if(s<1000)  d=5;                                  
                     else  if(s<2000)  d=8;                                  
                              else  if(s<3000)  d=10;                                 
                                       else  d=15;   
						   
   f = p * w * s * (1 - d / 100);         
   printf("freight=%10.2f\n",f);        
   return 0;
}

在这里插入图片描述

#include <stdio.h>
int main()
{
  char ch;
  scanf("%c",&ch);
  ch=(ch>='A' && ch<='Z')?(ch+32):ch;
  printf("%c\n",ch);
  return 0;
}

在这里插入图片描述

#include <stdio.h>
int main()	
{int year,leap;
  printf("enter year:"); scanf("%d",&year);
  if((year%4==0 && year%100!=0) || (year%400==0))
     leap=1;
  else  
     leap=0;
  if (leap)     printf("%d is ",year);
  else  printf("%d is not ",year);
  printf("a leap year.\n");
  return 0;
}

在这里插入图片描述

#include <stdio.h>
int main()
{ char grade;
   scanf("%c",&grade);
   printf("Your score:");
   switch(grade)
  { case 'A': printf("85~100\n");break;
     case 'B': printf("70~84\n");break;
     case 'C': printf("60~69\n");break;
     case 'D': printf("<60\n");break;    
	  default:  printf("enter data error!\n");
   }
   return 0;
 }

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值