华中科技大学标准C语言程序的设计及应用习题答案
合集下载
相关主题
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
1
(1)x|y = 0x002f
(2)x^y = 0x0026
(3)x&y = 0x0009;
(4)~x+~y = 0xffc6
(5)x<<=3 0x0068
(6)y>>=4 0x0002
2
(1)6
(2)50
(3)1
(4)–16
(5)1
(6)20
3
(1)0
(2)1
(3)1
(4)4
(5)8
(6)1
4
(1)12
scanf("%d",&i);
if(i==0)
break;
if(i%2==0)
printf("the data %d is a even number.\n",i);
else
printf("the data %d is a odd number.\n",i);
}
}
2.6
#include <stdio.h>
(2)0
(3)1
(4)27
(5)1
(6)6
(7)24
(8)27
(9)–29
5
(1)0
(2)1
(3)1
(4)–3
(5)2
五.程序分析题
程序1
b=20 a=3600
程序2
第三章
一.填空题
1.s=6
2.96
3.(1) scanf("%c",&c);
(2) c-32更好的答案:c-('a'-'A')
2.1
main()
}
}
if(k==20)
printf("\nsorry,you failed!");
}
2.10
#include <stdio.h>
main()
{
int a,b,c;
int num;
for(a=0;a<10;a++)
{
for(b=0;b<10;b++)
{
for(c=1;c<10;c++)
{
num=a*100+b*10+c;
main()
{
int i;
int a=8,b=1;
int sum=0;
for(i=0;i<10;i++)
{
b+=3;
sum += a;
a+=b;
printf("a%8d b:%8d\n",a,b);
}
printf("The Sum Of Is:%d\n",sum);
}
2.7
#include <stdio.h>
{
int a,b;
printf("please input a & b:");
scanf("%d%d",&a,&b);
printf("\nmax is %d\n",(a>b)?a:b);
}
2.2
int max(int x,int y);
main()
{
int a,b,c,max;
printf("please input a & b & c:");
scanf("%d%d%d",&a,&b,&c);
max=a>b?a:b;
max=c>max?c:max;
printf("\nmax is %d\n",max);
}
2.3
main()
{
int i=0,sum=0;
while(i<=100)
{
sum+=i;
i++;
}
printf("1+2+3+......+100=%d\n",sum);
}
else if(a<b)
{
k++;
printf("\n%d:Bigger,guess again!\n",k);
}
else
{
printf("\nYou guess right,congraturation!") ;
printf("\nYou have guessed %d times",k);
break;
if((num%3==0)&&(a==5||b==5||c==5))
printf("%8d",num);
}
}
}
printf("\n\n\n");
}
2.11
#include <stdio.h>
main()
{
int i;
int a,b;
printf("please input a,b:");
scanf("%d%d",&a,&b);
for(i=a<b?a:b;i>0;i--)
{
if(a%i==0&&b%i==0)
{
printf("The max=%d",i);
break;
}
}
for(i=a>b?a:b;i>0;i++)
}
2.4
main()
{
int i;
int a=10,b=-3;
int c;
printf("%6d%6d",a,b);
for(i=2;i<10;i++)
{
c=3*b+a;
printf("%6d",c);
a=b;
b=c;
}
printf("\n");
}
2.5
main()
{
int i;
while(1)
{
printf("please input a data(0:exit):");
第二章
一.选择题
1.C 2.B D 3.A 4.A 5. D
6.C 7.D 8.C9.A 10.D
11.B 12.D 13.C 14.D 15.A
16.B 1来自百度文库.A 18.B100011 001111
二.判断题
1.错
2.错
3.错
4.错
三.填空题
1. B66
2. n1=%d\nn2=%d\n
3. 0
四.计算
randomize();
a=random(1001);/*create a random data(0-1000)*/
for(i=0;i<20;i++)
{
printf("please guess a number:");
scanf("%d",&b);
if(a>b)
{
k++;
printf("\n%d:Smaller,guess again!\n",k);
printf("%8d",b);
a/=10;
i++;
a1=a1*10+b;
}
printf("\n i:%ld a1:%ld\n",i,a1);
}
}
2.9
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
main()
{
int a,b,i,k=0;
main()
{
float x,y;
printf("please input x:");
scanf("%f",&x);
if(x<1.0)
y=x;
else if(x<10)
y=2*x-1;
else
y=3*x-11;
printf("y=%f\n",y);
}
2.8
#include <stdio.h>
main()
{
long a,i,b,a1;
while(1)
{
printf("please input data(1-99999):");
scanf("%ld",&a);
printf("a:%ld\n",a);
if(a<=0||a>=100000)
break;
i=0;
a1=0;
while(a!=0)
{
b=a%10;
(1)x|y = 0x002f
(2)x^y = 0x0026
(3)x&y = 0x0009;
(4)~x+~y = 0xffc6
(5)x<<=3 0x0068
(6)y>>=4 0x0002
2
(1)6
(2)50
(3)1
(4)–16
(5)1
(6)20
3
(1)0
(2)1
(3)1
(4)4
(5)8
(6)1
4
(1)12
scanf("%d",&i);
if(i==0)
break;
if(i%2==0)
printf("the data %d is a even number.\n",i);
else
printf("the data %d is a odd number.\n",i);
}
}
2.6
#include <stdio.h>
(2)0
(3)1
(4)27
(5)1
(6)6
(7)24
(8)27
(9)–29
5
(1)0
(2)1
(3)1
(4)–3
(5)2
五.程序分析题
程序1
b=20 a=3600
程序2
第三章
一.填空题
1.s=6
2.96
3.(1) scanf("%c",&c);
(2) c-32更好的答案:c-('a'-'A')
2.1
main()
}
}
if(k==20)
printf("\nsorry,you failed!");
}
2.10
#include <stdio.h>
main()
{
int a,b,c;
int num;
for(a=0;a<10;a++)
{
for(b=0;b<10;b++)
{
for(c=1;c<10;c++)
{
num=a*100+b*10+c;
main()
{
int i;
int a=8,b=1;
int sum=0;
for(i=0;i<10;i++)
{
b+=3;
sum += a;
a+=b;
printf("a%8d b:%8d\n",a,b);
}
printf("The Sum Of Is:%d\n",sum);
}
2.7
#include <stdio.h>
{
int a,b;
printf("please input a & b:");
scanf("%d%d",&a,&b);
printf("\nmax is %d\n",(a>b)?a:b);
}
2.2
int max(int x,int y);
main()
{
int a,b,c,max;
printf("please input a & b & c:");
scanf("%d%d%d",&a,&b,&c);
max=a>b?a:b;
max=c>max?c:max;
printf("\nmax is %d\n",max);
}
2.3
main()
{
int i=0,sum=0;
while(i<=100)
{
sum+=i;
i++;
}
printf("1+2+3+......+100=%d\n",sum);
}
else if(a<b)
{
k++;
printf("\n%d:Bigger,guess again!\n",k);
}
else
{
printf("\nYou guess right,congraturation!") ;
printf("\nYou have guessed %d times",k);
break;
if((num%3==0)&&(a==5||b==5||c==5))
printf("%8d",num);
}
}
}
printf("\n\n\n");
}
2.11
#include <stdio.h>
main()
{
int i;
int a,b;
printf("please input a,b:");
scanf("%d%d",&a,&b);
for(i=a<b?a:b;i>0;i--)
{
if(a%i==0&&b%i==0)
{
printf("The max=%d",i);
break;
}
}
for(i=a>b?a:b;i>0;i++)
}
2.4
main()
{
int i;
int a=10,b=-3;
int c;
printf("%6d%6d",a,b);
for(i=2;i<10;i++)
{
c=3*b+a;
printf("%6d",c);
a=b;
b=c;
}
printf("\n");
}
2.5
main()
{
int i;
while(1)
{
printf("please input a data(0:exit):");
第二章
一.选择题
1.C 2.B D 3.A 4.A 5. D
6.C 7.D 8.C9.A 10.D
11.B 12.D 13.C 14.D 15.A
16.B 1来自百度文库.A 18.B100011 001111
二.判断题
1.错
2.错
3.错
4.错
三.填空题
1. B66
2. n1=%d\nn2=%d\n
3. 0
四.计算
randomize();
a=random(1001);/*create a random data(0-1000)*/
for(i=0;i<20;i++)
{
printf("please guess a number:");
scanf("%d",&b);
if(a>b)
{
k++;
printf("\n%d:Smaller,guess again!\n",k);
printf("%8d",b);
a/=10;
i++;
a1=a1*10+b;
}
printf("\n i:%ld a1:%ld\n",i,a1);
}
}
2.9
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
main()
{
int a,b,i,k=0;
main()
{
float x,y;
printf("please input x:");
scanf("%f",&x);
if(x<1.0)
y=x;
else if(x<10)
y=2*x-1;
else
y=3*x-11;
printf("y=%f\n",y);
}
2.8
#include <stdio.h>
main()
{
long a,i,b,a1;
while(1)
{
printf("please input data(1-99999):");
scanf("%ld",&a);
printf("a:%ld\n",a);
if(a<=0||a>=100000)
break;
i=0;
a1=0;
while(a!=0)
{
b=a%10;