习题4-4
#include <stdio.h> int main(){ int a,b,c,maxn; scanf("%d%d%d",&a,&b,&c); if(a>b) maxn=a; else maxn=b; if(c>maxn) maxn=c; printf("%d",maxn); return 0; }习题4-5
#include <stdio.h> #include <math.h> int main(){ int a; do{ printf("请输入一个小于1000并大于0的正整数\n"); scanf("%d",&a); }while(a>=1000||a<=0); float ans=sqrt(a); printf("它的平方根为%f",ans); return 0; }习题4-6
#include <stdio.h> int main(){ int y,x; scanf("%d",&x); if(x<1) y=x; else if(1<=x&&x<10) y=2*x-1; else y=3*x-11; printf("%d",y); return 0; }习题4-7
#include <stdio.h> int main(){ int y,x; scanf("%d",&x); if(x<0) y=-1; else if(x==0) y=0; else y=1; printf("%d",y); return 0; }习题4-8
#include <stdio.h> int main(){ int x; scanf("%d",&x); if(x>90) putchar('A'); else if(x>80) putchar('B'); else if(x>70) putchar('C'); else if(x>60) putchar('D'); else putchar('E'); return 0; }习题4-9
#include <stdio.h> int main(){ int n,t,a,b; int digit; scanf("%d",&n); t=n; a=b=digit=0; while(t>0){ digit++; //digit记录n的位数 a=a*10+t; //a记录n的倒序写法 t/=10; } printf("%d\n",digit); while(digit>0){ printf("%d ",a); //将倒序数从低位到高位输出即为正序 a/=10; digit--; } printf("\n"); b=n; //a记录n的正序写法 while(b>0){ printf("%d ",b); //将正序数从低位到高位输出即为倒序 b/=10; } return 0; }附加1
#include <stdio.h> #include <stdlib.h> #include <time.h> int main(){ srand(time(0)); int a=rand()0+1; int b; printf("请输入一个数\n"); while(1){ scanf("%d",&b); if(a==b){ printf("你猜中了\n"); return 0; } else if(a<b) printf("你猜大了\n"); else printf("你猜小了\n"); } return 0; }附加2
#include <stdio.h> int main(){ float a,b; char sign; scanf("%f%c%f",&a,&sign,&b); switch (sign) { case '+': printf("%f",a+b); return 0; case '-': printf("%f",a-b); return 0; case '*': printf("%f",a*b); return 0; case '/': printf("%f",a/b); return 0; } return 0; }转载于:https://www.cnblogs.com/kangyupl/p/10621341.html
相关资源:c 实验报告