4、
#include<stdio.h> int main(){ int a,b,c; scanf("%d%d%d",&a,&b,&c); if(a>b){ if(a>c){ printf("max num is :%d\n",a); } else printf("max mun is:%d\n",c); } else{ if(b>c) printf("max num is:%d\n",b); else printf("max num is:%d\n",c); } return 0; }
5、
#include<stdio.h> #include<math.h> int main(){ int a; scanf("%d",&a); while(a<=0||a>=1000){ printf("Your input is illegal,please put again\n"); scanf("%d",&a); } a = sqrt(a); printf("a sqrt :%d\n",a); return 0; }
6、
#include<stdio.h> int main(){ int x,y; printf("please input x:"); scanf("%d",&x); if(x<1) y = x; else if(x>=1&&x<10) y = 2*x-1; else y = 3*x-11; printf("y = %d\n",y); return 0; }
8、
#include<stdio.h> int main(){ int grade; printf("Please input your score(0-100):"); scanf("%d",&grade); if(grade>=90) printf("grade is A\n"); else if(grade>=80) printf("grade is B\n"); else if(grade>=70) printf("grade is C\n"); else if(grade>=60) printf("grade is D\n"); else printf("grade is E\n"); return 0; }
9、
#include<stdio.h> int main(){ int a,b,num,renum = 0,count = 0; scanf("%d",&a); num = a; while(num){ num/=10; count++; } printf("The num length is:%d\n",count); while(count){ b=a%10; printf("Every bit number is:%d\n",b); renum=renum*10+b; a/=10; count--; } printf("The reversed number is:%d\n",renum); return 0; }
10、
#include<stdio.h> int main(){ long int a,p; scanf("%ld",&a); if(a>1000000) p = (a-1000000)*0.01+400000*0.015+200000*0.03+200000*0.05+100000*0.075+100000*0.1; else if(a>600000) p = (a-600000)*0.015+200000*0.03+200000*0.05+100000*0.075+100000*0.1; else if(a>400000) p = (a-400000)*0.03+200000*0.05+100000*0.075+100000*0.1; else if(a>20000) p = (a-200000)*0.05+100000*0.075+100000*0.1; else if(a>100000) p = (a-100000)*0.075+100000*0.1; else p = a*0.1; printf("profit is %ld\n",p); return 0; }
用switch把输入的数据比100000,从case(0)到case(10)defualt表示100w以上,case后面跟对应式子,并且输出,相应的选项做相应的值。
11、有点复杂,后期可能会改进。
#include<stdio.h> int main(){ int a,b,c,d; scanf("%d%d%d%d",&a,&b,&c,&d); if(a>b) if(a>c) if(a>d) printf("max:%d\n",a); else printf("max:%d\n",d); else if(c>d) printf("max:%d\n",c); else printf("max:%d\n",d); else if(b>c) if(b>d) printf("max:%d\n",b); else printf("max:%d\n",d); else if(c>d) printf("max:%d\n",c); else printf("max:%d\n",d); return 0;
12、
void calculate(double x, double y) { if (1 <= x && x <= 3 && 1 <= y && y <= 3) { x = abs(x) - 2; y = abs(y) - 2; double r = sqrt(x * x + y * y); if (r <= 1) { printf("该点坐标高度为10\n"); } else printf("该点坐标高度为0\n"); } else { printf("该点坐标高度为0\n"); } } int main() { while (1) { double x, y; printf("请输入x和y点的坐标:>"); scanf("%lf %lf", &x, &y); calculate(fabs(x), fabs(y)); } return 0; }
标签:int,max,else,grade,谭浩强,100000,课后,printf,C语言 From: https://www.cnblogs.com/gunancheng/p/17393807.html