标签:amp 习题 break nbsp float 正整数 core 表达 com
2、对于逻辑量表达式1表示真,0表示假。
对于逻辑量表达式非0表示真,0表示假。
3、值得注意的是c语言中的优先级,优先级由高到低依次为:
4、
1 #include<stdio.h> 2 int main() 3 { 4 int a,b,c,t; 5 scanf("%d,%d,%d",&a,&b,&c); 6 if(a<b) 7 {t=b; 8 a=b; 9 b=t;} 10 if(a<c) 11 {t=c; 12 a=c; 13 c=t;} 14 printf("最大的是:%d\n",a); 15 return 0; 16 }
法2:
1 #include<stdio.h> 2 int main() 3 { 4 int a,b,c,temp,max; 5 scanf("%d,%d,%d",&a,&b,&c); 6 temp=(a>b)?a:b; 7 max=(temp>c)?temp:c; 8 printf("最大的是:%d\n",max); 9 return 0; 10 }
5、
1 #include<stdio.h> 2 #include<math.h> 3 int main() 4 { 5 int a,b; 6 scanf("%d",&a); 7 if(a>=1000) 8 {printf("enter again:\n"); 9 scanf("%d",&a);} 10 b=sqrt(a); 11 printf("%d\n",b); 12 return 0; 13 }
8、
1 #include<stdio.h> 2 int main() 3 { 4 float score; 5 char grad; 6 printf("enter score:"); 7 scanf("%f",&score); 8 while(score>100||score<0) 9 {printf("enter again:"); 10 scanf("%f",&score); 11 } 12 switch((int)(score/10)) 13 {case 10: 14 case 9:grad=‘A‘;break; 15 case 8:grad=‘B‘;break; 16 case 7:grad=‘C‘;break; 17 case 6:grad=‘B‘;break; 18 case 5: 19 case 4: 20 case 3: 21 case 2: 22 case 1: 23 case 0:grad=‘E‘; 24 } 25 printf("成绩是:%5.1f,等级是: %c\n",score,grad); 26 return 0; 27 }
9、给一个不多于五位的正整数,奥球
求出它是几位数,分别是出每一位数字,按逆序输出各位数字
1 #include<stdio.h> 2 #include<math.h> 3 int main() 4 { 5 int num,indiv,ten,hundred,thousand,ten_thousand,place; 6 printf("请输入一个不多于5位的整数:"); 7 scanf("%d",&num); 8 if(num>9999) 9 place=5; 10 else 11 if(num>999) 12 place=4; 13 else 14 if(num>99) 15 place=3; 16 else 17 if(num>9) 18 place=2; 19 else 20 place=1; 21 printf("位数:%d\n",place); 22 printf("每位数字为\n"); 23 ten_thousand=num/10000; 24 thousand=(int)(num-ten_thousand*10000)/1000; 25 hundred=(int)(num-ten_thousand*10000-thousand*1000)/100; 26 ten=(int)(num-ten_thousand*10000-thousand*1000-hundred*100)/10; 27 indiv=(int)(num-ten_thousand*10000-thousand*1000-hundred*100-ten*10); 28 switch(place) 29 { 30 case 5:printf("%d,%d,%d,%d,%d",ten_thousand,thousand,hundred,ten,indiv); 31 printf("\n反序数字为\n"); 32 printf("%d%d%d%d%d",indiv,ten,hundred,thousand,ten_thousand); 33 break; 34 case 4:printf("%d,%d,%d,%d",thousand,hundred,ten,indiv); 35 printf("\n反序数字为\n"); 36 printf("%d%d%d%d",indiv,ten,hundred,thousand); 37 break; 38 case 3:printf("%d,%d,%d",hundred,ten,indiv); 39 printf("\n反序数字为\n"); 40 printf("%d%d%d",indiv,ten,hundred); 41 break; 42 case 2:printf("%d,%d",ten,indiv); 43 printf("\n反序数字为\n"); 44 printf("%d%d",indiv,ten); 45 break; 46 case 1:printf("%d",indiv); 47 printf("\n反序数字为\n"); 48 printf("%d",indiv); 49 break; 50 } 51 return 0; 52 }
12、判断是否在塔外
1 #include<stdio.h> 2 int main() 3 { 4 int h=10; 5 float x1=2,y1=2,x2=-2,y2=2,x3=-2,y3=-2,x4=2,y4=-2,x,y,d1,d2,d3,d4; 6 printf("请输入x,y: "); 7 scanf("%f,%f",&x,&y); 8 d1=(x-x4)*(x-x4)+(y-y4); 9 d2=(x-x1)*(x-x1)+(y-y1)*(y-y1); 10 d3=(x-x2)*(x-x2)+(y-y2)*(y-y2); 11 d4=(x-x3)*(x-x3)+(y-y3)*(y-y3); 12 if(d1>1&&d2>1&&d3>1&&d4>1) 13 h=0; 14 printf("高度为:%d\n",h); 15 return 0; 16 }
标签:amp 习题 break nbsp float 正整数 core 表达 com
原文地址:https://www.cnblogs.com/1998wdq/p/11221578.html