3.
(1)0
(2)1(3)1(4)0(5)1
4.c=1
5.-4
6.1
7.5,0,3
8.5
9.123
10.(cvb=='y'||cvb=='Y')&&(work>=3||college=='y'||college=='Y')&&age<=35
4.3改错题(略)
4.4编程题
1.答
#include"stdio.h"
#include"math.h"
main()
{
doublea,b,c,p,area;
scanf("%lf%lf%lf",&a,&b,&c);
printf("三角形的三边为:
%.llf,%.1lf,%.1lf\n",a,b,c);
if(a+b>c&&a+c>b&&b+c>a)
{p=(a+b+c)/2;
area=sqrt(p*(p-a)*(p-b)*(p-c));
printf("三角形的面积为%.2lf\n",area);
}
else
printf("不能构成三角形\n");
}
2.答:
#include"stdio.h"
main()
{intx,y;
scanf("%d,%d",&x,&y);
if(x*x+y*y>1000)
printf("%d\n",(x*x+y*y)/100);
else
printf("%d\n",x+y);
}
3.答:
#include"stdio.h"
#include"math.h"
main()
{doublex,y;
scanf("%lf",&x);
if(x<-2)
y=x*x-sin(x);
elseif(x<=2)
y=pow(2,x)+x;
else
y=sqrt(x*x+x+1);
printf("x=%.2lfy=%.2lf\n",x,y);
}
4.答:
#include"stdio.h"
main()
{longge,shi,qian,wan,x;
scanf("%ld",&x);
wan=x/10000;
qian=x%10000/1000;
shi=x%100/10;
ge=x%10;
if(ge==wan&&shi==qian)/*个位等于万位并且十位等于千位*/
printf("thisnumberisahuiwen\n");
else
printf("thisnumberisnotahuiwen\n");
}
5.答:
#include"stdio.h"
main()
{floatp,w,s,d,f;
scanf("%f,%,%f",p,s,w);
if(s>3000)d=0.15
elseif(s>=2000)d=0.1;
elseif(s>=1000)d=0.08;
elseif(s>=500)d=0.05;
elseif(s>=250)d=0.02;
elsed=0
f=p*w*s*(1-d);
printf("%f",f);
}
6.答:
#include"stdio.h"
main()
{intyear,money;
charx;
printf("是否是本公司产品(y/n):
");
scanf("%c",&x);
if(x=='y'||x=='Y')
{printf("产品使用的年限:
");
scanf("%d",&year);
if(year<=1)money=0;
elseif(year<8)money=50;
elsemoney=100;
printf("产品保修额是:
%d\n",money);
}
else
{money=200;
printf("不是本公司产品,产品保修额是:
%d\n",money);
}
}
7.答:
#include"stdio.h"
main()
{intmoney,num1,num2;
printf("请输入取款额(≤2000):
");
scanf("%d",&money);
if(money>2000)printf("请输入取款额数≤2000!
\n");
else
if(money%50==0)
{num1=money/100;
num2=(money-num1*100)/50;
printf("需支付100元:
%d张\n",num1);
printf("需支付50元:
%d张\n",num2);
}
else
printf("输入钱数必须是50的倍数!
\n");
}
习题5
5.1单选题
CDABAABDDBDBCB
5.2填空题
1.20
2.333
3.
(1)i<10或i<=9
(2)j%3!
=0
4.
(1)flag*(float)k/(k+1)或1.0*flag*k/(k+1)
(2)flag=-flag
5.
(1)max=x
(2)x!
=-1(3)scanf("%d",&x)
6.
(1)x<=9或x<10
(2)y=9-x
5.3改错题(略)
5.4编程题
1.答:
(1)for循环,其他略
#include"stdio.h"
main()
{inti,s=0;
for(i=1;i<=100;i++)
s+=i*i;
printf("%d\n",s);
}
(2)for循环,其他略
#include"stdio.h"
main()
{inti=1,p=1;
doubles=1;
do
{
s+=1.0/p;
p*=++i;
}while(1.0/p>1e-6);
printf("%lf",s);
}
2.答:
#include"stdio.h"
main()
{intm,n,t,a,b;
scanf("%d,%d" ,&m,&n) ;
if(m{t=m ;m=n ;n=t ;}
a=m;
b=n;
t=m%n ;
while(t)
{m=n ;n=t ;t=m%n;}
printf("%d",n);
}
3.答:
#include"stdio.h"
main()
{intx,y,s=1;
scanf("%d,%d",&x,&y);
for(;y>0;y--)s*=x;
printf("%d,%d,%d\n",s%10,s/10%10,s/100%10);
}
4.答:
#include"stdio.h"
main()
{intx,y,z;
for(x=1;x<20;x++)
for(y=1;y<33;y++)
{z=100-x-y;
if((z%3)==0&&(5*x+3*y+z/3)==100)
printf("x=%d,y=%d,z=%d\n",x,y,z);
}
}
5.答:
(a)
#include"stdio.h"
main()
{intj,k;
for(j=1;j<=4;j++)
{for(k=1;k<=4-j;k++)printf("");
printf("****");
printf("\n");
}
}
(b)
#include"stdio.h"
main()
{intj,k ;
for(j=1 ;j<=4 ;j++)
{for(k=1;k<=4-j;k++)printf("");
for(k=1 ;k<=2*j-1 ;k++)
printf("*") ;
printf("\n") ;
}
}
6.答:
程序分析:
利用for循环控制在100~999之间,对每个数分解出个位、十位、百位。
#include
main()
{
inti,j,k,n;
printf("waterflower'numberis:
");
for(n=100;n<1000;n++)
{
i=n/100;/*分解出百位*/
j=n/10%10;/*分解出十位*/
k=n%10;/*分解出个位*/
if(n==i*i*i+j*j*j+k*k*k)
{
printf("%-5d",n);
}
}
printf("\n");
}
7.答:
#include
main()
{
intx;
for(x=1000;x>=3;x--)
if(x%3==1&&x%5==2&&x%7==3)
{
printf("该校的学生人数是:
%d人\n",x);
break;
}
}
8.答:
#include
main()
{
intx=12,i=1;
while
(1)
{if((x+20+i)==2*(x+i))break;
i++;
}
printf("小明母亲在%d年后比小明的年龄大一倍\n",i);
printf("那时小明年龄是:
%d岁,小明母亲年龄是:
%d岁\n",x+i,x+20+i);
}
习题6
6.1单选题
DBCCBBDC
6.2填空题
1.c
2.60
3.100010
4.16
6.3编程题
1.答:
#include"stdio.h"
#include"math.h"
#defineF(a)a*a+sqrt(3*a*a+2*a+1)
main()
{floatx,f;
scanf("%f",&x);
f=4.5/F(exp(x))+F(cos(x))+F(sqrt(x))/F(x*x);
printf("%f\n",f);
}
习题7
7.1单选题
BCADACCCDABCBDB
7.2填空题
1.
(1)2345
(2)10010(3)QuickC
(4)10000
01000
00100
00010
00001
(5)Language(6)LanguageProgramming
2.
(1)j+=2
(2)a[i]>a[j]
3.
(1)i=1
(2)x[i-1]
7.3改错题(略)
7.4编程题
1.答:
#defineN10
#include"stdio.h"
main()
{inta[N]={1,2,3,4,5,6,7,8,9,10,osum=0,qsum=0,j;
for(j=0;j<10;j++)
if(j%2)qsum+=a[j];
elseosum+=a[j];
printf("osum=%d,qsum=%d\n",osum,qsum);
}
2.答:
#defineN10
#include"stdio.h"
main()
{inta[N]={10,20,30,40,50,60,70,80,90},j,k,x;
scanf("%d",&x);
for(j=0;jif(xif(j==N)a[N-1]=x;
else
{for(k=N-1;k>j;k--)
a[k]=a[k-1];
a[j]=x;}
for(j=0;jprintf("%d",a[j]);
}
3.答:
#defineM3
#include"stdio.h"
main()
{inta[M][M]={{1,2,3},{2,4,5},{3,5,6}},j,k,flag=1;;
for(j=0;jfor(k=0;kif(a[j][k]!
=a[k][j]){flag=0;break;}
if(flag)printf("ok");
elseprintf("NO");
}
4.答:
#include"stdio.h"
#include"string.h"
main()
{charc1[10],c2[10],j;
gets(c1);gets(c2);
for(j=0;(c1[j]==c2[j])&&c1[j]&&c2[j];j++);
if(c1[j]>c2[j])printf("%d\n",1);
if(c1[j]if(c1[j]==c2[j])printf("%d\n",0);
}
5.答:
#include"stdio.h"
#include"string.h"
#defineM3
#defineN80
main()
{chara[M][N],j,k,n[5]={0};
for(j=0;jgets(a[j]);
for(j=0;jfor(k=0;a[j][k];k++)
if(a[j][k]>='A'&&a[j][k]<='Z')n[0]++;
elseif(a[j][k]>='a'&&a[j][k]<='z')n[1]++;
elseif(a[j][k]>='0'&&a[j][k]<='9')n[2]++;
elseif(a[j][k]=='')n[3]++;
else
n[4]++;
for(j=0;j<5;j++)
printf("%4d",n[j]);
}
习题8
8.1单选题
DBDACBACCC
8.2填空题
1.
(1)2,1
(2)10#30#(3)FOUR,P(4)60
2.
(1)49
(2)2(3)2
(4)(5)
8.3改错题(略)
8.4编程题
1.答:
#include"stdio.h"
main()
{intn1,n2,n3,t;
int*p1,*p2,*p3;
printf("pleaseinput3number:
n1,n2,n3:
");
scanf("%d,%d,%d",&n1,&n2,&n3);
p1=&n1;
p2=&n2;
p3=&n3;
if(*p1>*p2){t=*p1;*p1=*p2;*p2=t;}
if(*p1>*p3){t=*p1;*p1=*p3;*p3=t;}
if(*p2>*p3){t=*p2;*p2=*p3;*p3=t;}
printf("thesortednumbersare:
%d,%d,%d\n",n1,n2,n3);
}
2.答:
#include"stdio.h"
#defineN3
main()
{inta[N],*p=a;
for(;p-ascanf("%d",p);
p=a+N-1;
for(;p-a>=0;p--)
printf("%d",*p);
}
3.答:
#include"stdio.h"
main()
{inta[10];
intj,minl=0,maxl=0;
for(j=0;j<10;j++)
scanf("%d",a+j);
for(j=0;j<10;j++)
{if(a[maxl]<*(a+j))maxl=j;
if(a[minl]>*(a+j))minl=j;
}
j=a[0];a[0]=a[minl];a[minl]=j;
j=a[9];a[9]=a[maxl];a[maxl]=j;
for(j=0;j<10;j++)
printf("%d",*(a+j));
}
4.答:
输入阵列如下:
1234
5678
9101112
输出阵列如下:
1211109
8765
4321
#defineM3
#defineN4
#include"stdio.h"
main()
{inta[M][N]={1,2,3,4,5,6,7,8,9,10,11,12},k,j,*p=&a[0][0],t;
for(k=0,j=M*N-1;k{t=*(p+k);*(p+k)=*(p+j);*(p+j)=t;}
for(k=0 ;k{for(j=0 ;jprintf("%4d",a[k][j]);
XX文库-让每个人平等地提升自我printf("\n");
}
}
5.答:
#include"stdio.h"
main()
{
intlen;
charstr[20],*p=str;
printf("pleaseinputastring:
\n");
scanf("%s",str);
len=0;
while(*p!
='\0