c语言答案 c语言设计第四版答案

Ch31.#include "stdio.h"main(){int n,i;double r,p=1;scanf("%d%lf",&n,&r);for(i=1;ib)max=a;else max=b;if(max=1000){printf("the date error,please input again:"); scanf("%d",&a);}sq=sqrt(a);printf("the square root is:%dn",sq);}6.#include "stdio.h"#include "math.h"main(){int x,y;scanf("%d",&x);if(x=10) y=3*x-11; else y=2*x-1;printf("x=%d,y=%dn",x,y);}8.#include "stdio.h"#include "math.h"main(){int score,g;scanf("%d",&score);g=score/10;switch(g){case 10:case 9:printf("you grade is A");break;case 8:printf("you grade is B");break;case 7:printf("you grade is C");break;case 6:printf("you grade is D");break;case 5:case 4:case 3:case 2:case 1:case 0:printf("you grade is E");break;default:printf("you input is error!");break;}}9.解法一:#include "stdio.h"main(){long date;int a,b,c,d,e;scanf("%ld",&date);a=date/10000;b=date%10000/1000;c=date%1000/100;d=date%100/10;e=date%10;if(a!=0) printf("the date include 5 numbers,%ld %d%d%d%d%d",date,e,d,c,b,a);else if(b!=0) printf("the date include 4 numbers,%ld %d%d%d%d",date,e,d,c,b); else if(c!=0) printf("the date include 3 numbers,%ld %d%d%d",date,e,d,c); else if(d!=0) printf("the date include 2 numbers,%ld %d%d",date,e,d); else printf("the date include 1 numbers,%ld %d",date,e);}解法二:#include "stdio.h"main(){long date,ge;int num=0;scanf("%ld",&date);printf("%ldn",date);while(date!=0){ge=date%10;date/=10;num++;printf("%d",ge);}printf("nthe date include %d numbers.n",num);}解法三:#include "stdio.h"main(){long date,ge,dateni=0,dat;int num=0;scanf("%ld",&date);dat=date;while(date!=0){ge=date%10;date/=10;num++;dateni=dateni*10+ge;}printf("the date include %d numbers.n",num);printf("yuanxu:%ldn",dat);printf("nixu:%ldn",dateni);}解法四:#include main() { long num; int indiv,ten,hundred,thousand,ten_thousand,place; scanf("%ld",&num); if (num>9999) place=5; else if(num>999) place=4; else if(num>99) place=3; else if(num>9) place=2; else place=1; printf("place =%dn", place); ten_thousand=num/10000; thousand=num/1000%10; hundred=num/100%10; ten=num%100/10; indiv=num%10; switch(place) { case 5: printf("%d,%d,%d,%d,%d",ten_thousand,thousand,hundred,ten,indiv); printf("n反序数字为;"); printf("%d%d%d%d%dn",indiv,ten,hundred,thousand,ten_thousand); break; case 4: printf("%d,%d,%d,%d",thousand,hundred,ten,indiv); printf("n反序数字为:"); printf("%d%d%d%dn",indiv,ten,hundred,thousand); break; case 3: printf("%d,%d,%d",hundred,ten,indiv); printf("n反序数字为:"); printf("%d%d%dn",indiv,ten,hundred); break; case 2: printf("%d,%d",ten,indiv); printf("n反序数字为:"); printf("%d%dn",indiv,ten); break; case 1: printf("%d",indiv); printf("n反序数字为:"); printf("%dn",indiv); break; } } 10.解法一:#include "stdio.h"main(){long lirun;double jiangjin;scanf("%ld",&lirun);if(lirun main() { long i; float bonus,bon1,bon2,bon4,bon6,bon10; bon1=100000*0.1; /*利润为10万元时的奖金*/ bon2=bon1+100000*0.075; /*利润为20万元时的奖金*/ bon4=bon2+200000*0.05; /*利润为40万元时的奖金*/ bon6=bon4+200000*0.03; /*利润为60万元时的奖金*/ bon10=bon6+400000*0.015; /*利润为100万元时的奖金*/ printf("请输入利润i:"); scanf("%ld",&i); if(i main() { long i; float bonus, bon1, bon2, bon4, bon6, bon10; int c; bon1=100000*0.1; bon2=bon1+100000*0.075; bon4=bon2+200000*0.05; bon6=bon4+200000*0.03; bon10=bon6+400000*0.015; printf("请输入利润i:"); scanf("%ld",&i); c=i/100000; if(c>10) c=10; switch(c) { case 0: bonus=1*0.1;break; case 1: bonus=bon1+(i-100000)*0.075;break; case 2 : case 3: bonus=bon2+(i-200000)*0.05; break; case 4: case 5: bonus=bon4+(i-400000)*0.03;break; case 6: case 7: case 8: case 9: bonus=bon6+(i-600000)*0.015;break; case 10: bonus=bon10+(i-1000000)*0.01; } printf("奖金是%10.2f",bonus); } 11.#include main() { int t,a,b,c,d; printf("please input 4 int numbers:"); scanf("%d%d%d%d",&a,&b,&c,&d); if(a>b) {t=a; a=b; b=t;} if(a>c) {t=a; a=c; c=t;} if(a>d) {t=a; a=d; d=t;} if(b>c) {t=b; b=c; c=t;} if(b>d) {t=b; b=d; d=t;} if(c>d) {t=c; c=d; d=t;} printf("the result:n"); printf("%d %d %d %dn",a,b,c,d); }12.#include "stdio.h"#include "math.h"main(){double x,y,l,h,a,b;scanf("%lf%lf",&x,&y);a=fabs(x)-2;b=fabs(y)-2;l=sqrt(a*a+b*b);if(ln){t=m;m=n;n=t;}for(i=m;i>0;i--) if(m%i==0&&n%i==0) {s=i;break;}for(j=n;;j++) if(j%m==0&&j%n==0){t=j;break;}printf("gongyue=%ld,gongbei=%ldn",s,t); }4.#include"stdio.h" main() {char c;int i=0,j=0,k=0,l=0; while((c=getchar())!='n') {if(c>=65&&c=97&&c=48&&c=0.00001); printf("%.3fn",x1); }14.#include"stdio.h" main() {double x,y;x=1.5; do{y=2*x*x*x-4*x*x+3*x-6; x=x-y/(6*x*x-8*x+3);} while(y!=0); printf("x=%.3fn",x); }15.#include"stdio.h" #include"math.h" main() {double x1,x2,m,y1,ym;x1=-10;x2=10;while(fabs(x1-x2)>0.0001){m=(x1+x2)/2;y1=2*x1*x1*x1-4*x1*x1+3*x1-6;ym=2*m*m*m-4*m*m+3*m-6;if(ym==0){x1=x2=m;break;}if(y1*ym>0)x1=m;else x2=m;}m=(x1+x2)/2;printf("%.3lfn",m); }16.#include"stdio.h" #include"math.h" main() {int i,j,k; for(i=1;i%cnB%cnC%cn",i,j,k);}Ch61. #include "stdio.h"main(){int n,i,k,count=0;for(n=1;nk){printf("%d ",n);count++;if(count%5==0)printf("n");}}printf("n");}2.#include "stdio.h"main(){int a[10],i,j,max,t;for(i=0;in){wei=i;break;}for(i=0;i0;i--) if(a[i]n)) { i=i+2; j=j-1; } else { if(in) j=1; } if(a[i][j]==0) a[i][j]=k; else { i=i+2; j=j-1; a[i][j]=k; } } for(i=1;i=a[i][j+1]) b[k]=a[i][j+1]=a[i][j]; else b[k]=a[i][j+1]; } for(j=0,l=0;ja[7]) { if(a[i]-m==0) { printf("it is at (%d)n",i+1); break; } i++;} else {printf("it is at 8n"); break;}} if(fabs(i-7)-8==0) printf("There is notn"); }10.解法一:#include "stdio.h" main() {int i,j=0,k=0,l=0,m=0,n=0;char str0[301],str1[100],str2[100]; gets(str0);gets(str1);gets(str2); strcat(str0,str1);strcat(str0,str2);for(i=0;str0[i]!='';i++) {if(str0[i]>=65&&str0[i]=97&&str0[i]=48&&str0[i]=65&&str[i][j]=97&&str[i][j]=48&&str[i][j]=65&&str1[i]=97&&str1[i] #include main() { int i,resu; char s1[100],s2[100]; printf("n input string1:"); gets(s1); printf("n Input string2:"); gets(s2); i=0; while(s1[i]==s2[i]&&s1[i]!='') i++; if(s1[i]==''&&s2[i]=='0') resu=0; else resu=s1[i]-s2[i]; printf("n result:%dn",resu); }15.#include "stdio.h" main() { char s1[80],s2[80]; int i; printf("Input s2:"); scanf("%s",s2); for(i=0;i=1;i--) {if(m%i==0&&n%i==0) {t=i; break;}} return(t); } int minbeishu(int m,int n) {int i,t,k; if(m>=n) k=m; else k=n;i=k; while(1){if(i%m==0&&i%n==0) {t=i;break;}i++;} return t; } main() {int a,b,max,min; printf("enter two number is: "); scanf("%d,%d",&a,&b); max=maxyueshu(a,b); min=minbeishu(a,b); printf("max=%d,min=%dn",max,min); }解法二:#include "stdio.h" int maxyueshu(int m,int n) { int t,r; if(m>n) {t=m;m=n;n=t;}r=n%m;while(r!=0){n=m;m=r;r=n%m;}return m; } int minbeishu(int m,int n) {int t,k; k=maxyueshu(m,n);t=m*n/k;return t; } main() {int a,b,max,min; printf("enter two number is: "); scanf("%d,%d",&a,&b); max=maxyueshu(a,b); min=minbeishu(a,b); printf("max=%d,min=%dn",max,min); }2.#include"stdio.h"#include"math.h"float shigen(float a,float b,float q) {float x1,x2; x1=(-b+sqrt(q))/(2*a); x2=(-b-sqrt(q))/(2*a); printf("two shigen is x1=%.3f and x2=%.3fn",x1,x2); } float denggen(float a,float b) {float x; x=-b/(2*a); printf("denggen is x=%.3fn",x); } float xugen(float a,float b,float q) {float x,y; x=-b/(2*a); y=sqrt(-q)/(2*a); printf("two xugen is x1=%.3f+%.3fi and x2=%.3f-%.3fin",x,y,x,y); } main() {float a,b,c,q; printf("input a b c is: "); scanf("%f,%f,%f",&a,&b,&c); printf("n"); q=b*b-4*a*c; if(q>0) shigen(a,b,q); else if(q==0) denggen(a,b); else xugen(a,b,q); }3.#include"stdio.h"int sushu(int m) {int i,t; for(i=2;i=65&&str[i]=97&&str[i]=48&&str[i]=97&&str[i]=65&&str[i]=t) strcpy(longword,word);} } main() {char str[100],longword[15]; gets(str); cechang(str,longword); puts(longword); }11.#include"stdio.h"paixu(int x[]) {int i,j,t; for(j=0;jx[i+1]) {t=x[i+1];x[i+1]=x[i];x[i]=t;} } main() {int y[10];int i; for(i=0;i

c语言答案 c语言设计第四版答案
  

爱华网本文地址 » http://www.413yy.cn/a/25101013/173654.html

更多阅读

第四套人民币最新价格表 第四套人民币价值

第四套人民币最新价格表_第四版人民币回收价格(2014年5月16号)摘要:   人民币收藏网(http://www.aa9b.cn/jiage/)提供第四套人民币最新价格表_第四版人民币回收价格_第四套人民币价格表2014(2014年5月16日)北京报价。 名称 面值 市场参

声明:《c语言答案 c语言设计第四版答案》为网友丢不起的信仰分享!如侵犯到您的合法权益请联系我们删除