c语言第四章的答案
展开全部
//如果是老谭的,你看看下面是否是你要的。
第三章 3.4
main()
{int a,b,c;
long int u,n;
float x,y,z;
char c1,c2;
a=3;b=4;c=5;
x=1.2;y=2.4;z=-3.6;
u=51274;n=128765;
c1='a';c2='b';
printf("\n");
printf("a=%2d b=%2d c=%2d\n",a,b,c);
printf("x=%8.6f,y=%8.6f,z=%9.6f\n",x,y,z);
printf("x+y=%5.2f y+z=%5.2f z+x=%5.2f\n",x+y,y+z,z+x);
printf("u=%6ld n=%9ld\n",u,n);
printf("c1='%c'or %d(ASCII)\n",c1,c1);
printf("c2='%c'or %d(ASCII)\n",c2,c2);
}
3.5
57
5 7
67.856400,-789.123962
67.856400,-789.123962
67.86 -789.12,67.856400,-789.123962,67.856400,-789.123962
6.785640e+001,-7.89e+002
A,65,101,41
1234567,4553207,d687
65535,177777,ffff,-1
COMPUTER, COM
3.6
a=3 b=7/
x=8.5 y=71.82/
c1=A c2=a/
3.7
10 20Aa1.5 -3.75 +1.4,67.8/
(空 3)10(空3)20Aa1.5(空1)-3.75(空1)(随意输入一个数),67.8 回车
3.8
main()
{float pi,h,r,l,s,sq,sv,sz;
pi=3.1415926;
printf("input r,h\n");
scanf("%f,%f",&r,&h);
l=2*pi*r;
s=r*r*pi; sq=4*pi*r*r;
sv=4.0/3.0*pi*r*r*r;
sz=pi*r*r*h;
printf("l=%6.2f\n",l);
printf("s=%6.2f\n",s);
printf("sq=%6.2f\n",sq);
printf("vq=%6.2f\n",sv);
printf("vz=%6.2f\n",sz);
}
3.9
main()
{float c,f;
scanf("%f",&f);
c=(5.0/9.0)*(f-32);
printf("c=%5.2f\n",c);
}
3.10
#include"stdio.h"
main()
{char c1,c2;
scanf("%c,%c",&c1,&c2);
putchar(c1);
putchar(c2);
printf("\n");
printf("%c%c\n",c1,c2);
}
第四章
4.3
(1)0 (2)1 (3)1 (4)0 (5)1
4.4
main()
{int a,b,c;
scanf("%d,%d,%d",&a,&b,&c);
if(a<b)
if(b<c)
printf("max=%d\n",c);
else
printf("max=%d\n",b);
else if(a<c)
printf("max=%d\n",c);
else
printf("max=%d\n",a);
}
main() {int a,b,c,temp,max;
scanf("%d,%d,%d",&a,&b,&c);
temp=(a>b)?a:b;
max=(c>temp)?c:temp;
printf("max=%d",max);
}
4.5
main()
{int x,y;
scanf("%d",&x);
if(x<1)y=x;
else if(x<10)y=2*x-1;
else y=3*x-11;
printf("y=%d",y);
}
4.6
main()
{int score,temp,logic;
char grade;
logic=1;
while(logic)
{scanf("%d",&score);
if(score>=0&&score<=100)logic=0;
}
if(score==100)
temp=9;
else
temp=(score-score%10)/10;
switch(temp)
{case 9:grade='A';break;
case 8:grade='B';break;
case 7:grade='C';break;
case 6:grade='D';break;
case 5:
case 4:
case 3:
case 2:
case 1:
case 0:grade='E';
}
printf"score=%d,grade=%c",score,grade);
}
4.7 main()
{long int 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=%d\n",place);
ten_thousand=num/10000;
thousand=(num-ten_thousand*10000)/1000;
hundred=(num-ten_thousand*10000-thousand*1000)/100;
ten=(num-ten_thousand*10000-thousand*1000-hundred*100)/10;
indiv=num-ten_thousand*10000-thousand*1000-hundred*100-ten*10;
switch(place)
{case 5:printf("%d,%d,%d,%d,%d\n",ten_thousand,thousand,hundred,ten,indiv);
printf("%d,%d,%d,%d,%d\n",indiv,ten,hundred,thousand,ten_thousand);
break;
case 4:printf("%d,%d,%d,%d\n",thousand,hundred,ten,indiv);
printf("%d,%d,%d,%d\n",indiv,ten,hundred,thousand);
break;
case 3:printf("%d,%d,%d\n",hundred,ten,indiv);
printf("%d,%d,%d\n",indiv,ten,hundred);
break;
case 2:printf("%d,%d\n",ten,indiv);
printf("%d,%d\n",indiv,ten);
break;
case 1:printf("%d\n",indiv);
printf("%d\n",indiv);
}
}
4.8
main()
{long i;
float bonus,bon1,bon2,bon4,bon6,bon10;
bon1=100000*0.1;
bon2=bon1+100000*0.075;
bon4=bon2+200000*0.05;
bon6=bon4+200000*0.03;
bon10=bon6+400000*0.015;
scanf("%ld",&i);
if(i<=1e5)bonus=i*0.1;
else if(i<=2e5)bonus=bon1+(i-100000)*0.075; else if(i<=4e5)bonus=bon2+(i-200000)*0.05;
else if(i<=6e5)bonus=bon4+(i-400000)*0.03;
else if(i<=1e6)bonus=bon6+(i-600000)*0.015;
else bonus=bon10+(i-1000000)*0.01;
printf("bonus=%10.2f",bonus);
}
main()
{long i;
float bonus,bon1,bon2,bon4,bon6,bon10;
int branch;
bon1=100000*0.1;
bon2=bon1+100000*0.075;
bon4=bon2+200000*0.05;
bon6=bon4+200000*0.03;
bon10=bon6+400000*0.015;
scanf("%ld",&i);
branch=i/100000;
if(branch>10)branch=10;
switch(branch)
{case 0:bonus=i*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("bonus=%10.2f",bonus);
}
4.9
main()
{int t,a,b,c,d;
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("%d %d %d %d\n",a,b,c,d);
}
4.10
main()
{int h=10;
float x,y,x0=2,y0=2,d1,d2,d3,d4;
scanf("%f,%f",&x,&y);
d1=(x-x0)*(x-x0)+(y-y0)*(y-y0);
d2=(x-x0)*(x-x0)+(y+y0)*(y+y0);
d3=(x+x0)*(x+x0)+(y-y0)*(y-y0);
d4=(x+x0)*(x+x0)+(y+y0)*(y+y0);
if(d1>1&&d2>1&&d3>1&&d4>1)h=0;
printf("h=%d",h);
}
第三章 3.4
main()
{int a,b,c;
long int u,n;
float x,y,z;
char c1,c2;
a=3;b=4;c=5;
x=1.2;y=2.4;z=-3.6;
u=51274;n=128765;
c1='a';c2='b';
printf("\n");
printf("a=%2d b=%2d c=%2d\n",a,b,c);
printf("x=%8.6f,y=%8.6f,z=%9.6f\n",x,y,z);
printf("x+y=%5.2f y+z=%5.2f z+x=%5.2f\n",x+y,y+z,z+x);
printf("u=%6ld n=%9ld\n",u,n);
printf("c1='%c'or %d(ASCII)\n",c1,c1);
printf("c2='%c'or %d(ASCII)\n",c2,c2);
}
3.5
57
5 7
67.856400,-789.123962
67.856400,-789.123962
67.86 -789.12,67.856400,-789.123962,67.856400,-789.123962
6.785640e+001,-7.89e+002
A,65,101,41
1234567,4553207,d687
65535,177777,ffff,-1
COMPUTER, COM
3.6
a=3 b=7/
x=8.5 y=71.82/
c1=A c2=a/
3.7
10 20Aa1.5 -3.75 +1.4,67.8/
(空 3)10(空3)20Aa1.5(空1)-3.75(空1)(随意输入一个数),67.8 回车
3.8
main()
{float pi,h,r,l,s,sq,sv,sz;
pi=3.1415926;
printf("input r,h\n");
scanf("%f,%f",&r,&h);
l=2*pi*r;
s=r*r*pi; sq=4*pi*r*r;
sv=4.0/3.0*pi*r*r*r;
sz=pi*r*r*h;
printf("l=%6.2f\n",l);
printf("s=%6.2f\n",s);
printf("sq=%6.2f\n",sq);
printf("vq=%6.2f\n",sv);
printf("vz=%6.2f\n",sz);
}
3.9
main()
{float c,f;
scanf("%f",&f);
c=(5.0/9.0)*(f-32);
printf("c=%5.2f\n",c);
}
3.10
#include"stdio.h"
main()
{char c1,c2;
scanf("%c,%c",&c1,&c2);
putchar(c1);
putchar(c2);
printf("\n");
printf("%c%c\n",c1,c2);
}
第四章
4.3
(1)0 (2)1 (3)1 (4)0 (5)1
4.4
main()
{int a,b,c;
scanf("%d,%d,%d",&a,&b,&c);
if(a<b)
if(b<c)
printf("max=%d\n",c);
else
printf("max=%d\n",b);
else if(a<c)
printf("max=%d\n",c);
else
printf("max=%d\n",a);
}
main() {int a,b,c,temp,max;
scanf("%d,%d,%d",&a,&b,&c);
temp=(a>b)?a:b;
max=(c>temp)?c:temp;
printf("max=%d",max);
}
4.5
main()
{int x,y;
scanf("%d",&x);
if(x<1)y=x;
else if(x<10)y=2*x-1;
else y=3*x-11;
printf("y=%d",y);
}
4.6
main()
{int score,temp,logic;
char grade;
logic=1;
while(logic)
{scanf("%d",&score);
if(score>=0&&score<=100)logic=0;
}
if(score==100)
temp=9;
else
temp=(score-score%10)/10;
switch(temp)
{case 9:grade='A';break;
case 8:grade='B';break;
case 7:grade='C';break;
case 6:grade='D';break;
case 5:
case 4:
case 3:
case 2:
case 1:
case 0:grade='E';
}
printf"score=%d,grade=%c",score,grade);
}
4.7 main()
{long int 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=%d\n",place);
ten_thousand=num/10000;
thousand=(num-ten_thousand*10000)/1000;
hundred=(num-ten_thousand*10000-thousand*1000)/100;
ten=(num-ten_thousand*10000-thousand*1000-hundred*100)/10;
indiv=num-ten_thousand*10000-thousand*1000-hundred*100-ten*10;
switch(place)
{case 5:printf("%d,%d,%d,%d,%d\n",ten_thousand,thousand,hundred,ten,indiv);
printf("%d,%d,%d,%d,%d\n",indiv,ten,hundred,thousand,ten_thousand);
break;
case 4:printf("%d,%d,%d,%d\n",thousand,hundred,ten,indiv);
printf("%d,%d,%d,%d\n",indiv,ten,hundred,thousand);
break;
case 3:printf("%d,%d,%d\n",hundred,ten,indiv);
printf("%d,%d,%d\n",indiv,ten,hundred);
break;
case 2:printf("%d,%d\n",ten,indiv);
printf("%d,%d\n",indiv,ten);
break;
case 1:printf("%d\n",indiv);
printf("%d\n",indiv);
}
}
4.8
main()
{long i;
float bonus,bon1,bon2,bon4,bon6,bon10;
bon1=100000*0.1;
bon2=bon1+100000*0.075;
bon4=bon2+200000*0.05;
bon6=bon4+200000*0.03;
bon10=bon6+400000*0.015;
scanf("%ld",&i);
if(i<=1e5)bonus=i*0.1;
else if(i<=2e5)bonus=bon1+(i-100000)*0.075; else if(i<=4e5)bonus=bon2+(i-200000)*0.05;
else if(i<=6e5)bonus=bon4+(i-400000)*0.03;
else if(i<=1e6)bonus=bon6+(i-600000)*0.015;
else bonus=bon10+(i-1000000)*0.01;
printf("bonus=%10.2f",bonus);
}
main()
{long i;
float bonus,bon1,bon2,bon4,bon6,bon10;
int branch;
bon1=100000*0.1;
bon2=bon1+100000*0.075;
bon4=bon2+200000*0.05;
bon6=bon4+200000*0.03;
bon10=bon6+400000*0.015;
scanf("%ld",&i);
branch=i/100000;
if(branch>10)branch=10;
switch(branch)
{case 0:bonus=i*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("bonus=%10.2f",bonus);
}
4.9
main()
{int t,a,b,c,d;
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("%d %d %d %d\n",a,b,c,d);
}
4.10
main()
{int h=10;
float x,y,x0=2,y0=2,d1,d2,d3,d4;
scanf("%f,%f",&x,&y);
d1=(x-x0)*(x-x0)+(y-y0)*(y-y0);
d2=(x-x0)*(x-x0)+(y+y0)*(y+y0);
d3=(x+x0)*(x+x0)+(y-y0)*(y-y0);
d4=(x+x0)*(x+x0)+(y+y0)*(y+y0);
if(d1>1&&d2>1&&d3>1&&d4>1)h=0;
printf("h=%d",h);
}
展开全部
好说 :北邮出版社的 《选择结构程序设计》
1: 0
2: 20
3: (x<30&&x>20)||(x<-100)
4: ***a=25,b=14,c=16***
5: 37
6: if(a<=b) printf("1");
else printf("2");
7、
#include<stdio.h>
void main()
{ char a,b,t1,t2;
scanf("%c,%c",&a,&b);
t1=a>b?a:b;
t2=a<b?a:b;
if((t1-t2)%2==0)printf("%c,%c",a+1,b+1);
else printf("%c,%c",a-1,b-1);
getch();
}
8、
#include<stdio.h>
void main()
{ int temp1=0,temp2=0,x,y,i=1;
printf("Please input (x,y): ");
scanf("%d,%d",&x,&y);
while((i*y)<=x)
{ if(x==(i*y)) {temp1=1;break;}
temp2=i;
i++;
}
if(temp1)
printf("%d / %d = %d",x,y,i);
else
printf("%d / %d---> shang=%d,yushu=%d",x,y,temp2,x-y*temp2);
getch();
}
9、
#include<stdio.h>
void main()
{ float x,y,m=0,n=0;
scanf("%f,%f",&x,&y);
n=(x-2)*(x-2);
m=(y-2)*(y-2);
if((m+n)<=1)
printf("(%.3f,%.3f)In the yuan",x,y);
else
printf("(%.3f,%.3f)out of the yuan",x,y);
getch();
}
10、
#include<stdio.h>
void main()
{ int temp=0,month,year;
printf("Please input (year,month): ");
scanf("%d,%d",&year,&month);
if((year%400==0)||(year%4==0&&year%100!=0))
temp=1;
if(month==2)
{ if(temp)printf("%d year %d month have 29 ",year,month);
else printf("%d year %d month have 28 ",year,month);
}
else if(month%2==0)
printf("%d year %d month have 30 ",year,month);
else printf("%d year %d month have 31 ",year,month);
getch();
}
11、
switch(a/10)
{ case 5:m=4;break;
case 4:m=3;break;
case 3:m=2;break;
case 2:m=1;break;
default:m=5;
}
12、
方法一:
#include<stdio.h>
void main()
{ int x,y;
scanf("%d",&x);
if(x<0&&x>-5)
y=x-1;
else if(x==0)
y=x;
else if(x>0&&x<8)
y=x+1;
printf("%d",y);
getch();
}
方法二:
#include<stdio.h>
void main()
{ int x,y;
scanf("%d",&x);
if(x<8&&x>-5)
{ if(x==0)y=x;
else if(x>0&&x<8) y=y=x+1;
else y=x-1;
printf("%d",y);
}
else printf("Input error!!!");
getch();
}
方法三:
#include<stdio.h>
void main()
{ int x,y,i;
scanf("%d",&x);
if(x<8&&x>-5)
{ if(x==0)i=1;
else if(x>0&&x<8) i=2;
else i=3;
}
else i=4;
switch(i)
{ case 1:y=x;printf("%d",y);break;
case 2:y=x+1;printf("%d",y);break;
case 3:y=x-1;printf("%d",y);break;
case 4:printf("Input error!!");break;
}getch();
}
1: 0
2: 20
3: (x<30&&x>20)||(x<-100)
4: ***a=25,b=14,c=16***
5: 37
6: if(a<=b) printf("1");
else printf("2");
7、
#include<stdio.h>
void main()
{ char a,b,t1,t2;
scanf("%c,%c",&a,&b);
t1=a>b?a:b;
t2=a<b?a:b;
if((t1-t2)%2==0)printf("%c,%c",a+1,b+1);
else printf("%c,%c",a-1,b-1);
getch();
}
8、
#include<stdio.h>
void main()
{ int temp1=0,temp2=0,x,y,i=1;
printf("Please input (x,y): ");
scanf("%d,%d",&x,&y);
while((i*y)<=x)
{ if(x==(i*y)) {temp1=1;break;}
temp2=i;
i++;
}
if(temp1)
printf("%d / %d = %d",x,y,i);
else
printf("%d / %d---> shang=%d,yushu=%d",x,y,temp2,x-y*temp2);
getch();
}
9、
#include<stdio.h>
void main()
{ float x,y,m=0,n=0;
scanf("%f,%f",&x,&y);
n=(x-2)*(x-2);
m=(y-2)*(y-2);
if((m+n)<=1)
printf("(%.3f,%.3f)In the yuan",x,y);
else
printf("(%.3f,%.3f)out of the yuan",x,y);
getch();
}
10、
#include<stdio.h>
void main()
{ int temp=0,month,year;
printf("Please input (year,month): ");
scanf("%d,%d",&year,&month);
if((year%400==0)||(year%4==0&&year%100!=0))
temp=1;
if(month==2)
{ if(temp)printf("%d year %d month have 29 ",year,month);
else printf("%d year %d month have 28 ",year,month);
}
else if(month%2==0)
printf("%d year %d month have 30 ",year,month);
else printf("%d year %d month have 31 ",year,month);
getch();
}
11、
switch(a/10)
{ case 5:m=4;break;
case 4:m=3;break;
case 3:m=2;break;
case 2:m=1;break;
default:m=5;
}
12、
方法一:
#include<stdio.h>
void main()
{ int x,y;
scanf("%d",&x);
if(x<0&&x>-5)
y=x-1;
else if(x==0)
y=x;
else if(x>0&&x<8)
y=x+1;
printf("%d",y);
getch();
}
方法二:
#include<stdio.h>
void main()
{ int x,y;
scanf("%d",&x);
if(x<8&&x>-5)
{ if(x==0)y=x;
else if(x>0&&x<8) y=y=x+1;
else y=x-1;
printf("%d",y);
}
else printf("Input error!!!");
getch();
}
方法三:
#include<stdio.h>
void main()
{ int x,y,i;
scanf("%d",&x);
if(x<8&&x>-5)
{ if(x==0)i=1;
else if(x>0&&x<8) i=2;
else i=3;
}
else i=4;
switch(i)
{ case 1:y=x;printf("%d",y);break;
case 2:y=x+1;printf("%d",y);break;
case 3:y=x-1;printf("%d",y);break;
case 4:printf("Input error!!");break;
}getch();
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
谭浩强的那本《c语言程序设计》不是每道题都有答案的吧,我记不太清楚了,好像有本书就是它的配套答案,你如果不愿意买书,我这里有《c语言程序设计》(第二版)谭浩强的课后习题源程序,也就是题解,我可以传给你,如果需要,站内联系。
你需要的资料已经发送至你邮箱,请注意查收。
你需要的资料已经发送至你邮箱,请注意查收。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询