第一章 习题答案
一、选择题
1~5:BDCDA 6~10:DABBB 11~12:CC
二、填空题
1、main()
2、函数首部 ,函数体
3、函数
4、编辑、编译、连接、运行
5、.cpp、.obj、 .exe
6、; 或 分号
2、函数首部 ,函数体
3、函数
4、编辑、编译、连接、运行
5、.cpp、.obj、 .exe
6、; 或 分号
三、编程题
#include <stdio.h> /* 包含标准库的信息 */
void main() /* 定义名为main 的函数,它不接受参数值 */
{ /* main函数的语句都被括在花括号中 */
printf("hello, world\n");
/* main 函数调用库函数printf 以显示字符序列,其中\n代表换行符 */
}
第二章 习题答案
{ /* main函数的语句都被括在花括号中 */
printf("hello, world\n");
/* main 函数调用库函数printf 以显示字符序列,其中\n代表换行符 */
}
第二章 习题答案
一、选择题
1~5:CBABB 6~10:CDCDD 11~15:CADBC 16~20:BDAAD
二、填空题
1、整型,实型,字符型,枚举类型
2、1
3、9
4、12353514
5、2,1
6、2,2
6、2,2
7、10 20 0
8、a=14
9、2,3,1
10、double
第三章 习题答案
第三章 习题答案
一、选择题
1~5:CBBBC 6~10:DDDBB
二、填空题
1、控制语句,表达式语句, 复合语句
2、 ;
3、{}
2、 ;
3、{}
4、1
5、a
6、c:dec=120,oct=170,hex=78,ASCII=x
7、32767,32767
8、10,A,10
9、3 3
10、
(1) 123.456001
(2) □□□□□□□ 123.456
(3) 123.4560
(4) 8765.456700
(5) □□□□□□ 8765.457
(6) 8765.4567
(7) 8765.4567
(3) 123.4560
(4) 8765.456700
(5) □□□□□□ 8765.457
(6) 8765.4567
(7) 8765.4567
三、编程题
1、参考答案:
#include <stdio.h>
void main()
{
int a,b,c;
long int u,n;
{
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);
}
2、参考答案:
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);
}
2、参考答案:
#include <stdio.h>
void main()
{
float a, b, c, t;
printf("please input a,b,c:\n");
scanf ("%f, %f, %f", &a, &b, &c);
t=(a+b+c)/3;
printf ("average of %6.2f、%6.2f and %6.2f is %6.2f\n",a,b,c,t);
}
3、参考答案:
void main()
{
float a, b, c, t;
printf("please input a,b,c:\n");
scanf ("%f, %f, %f", &a, &b, &c);
t=(a+b+c)/3;
printf ("average of %6.2f、%6.2f and %6.2f is %6.2f\n",a,b,c,t);
}
3、参考答案:
#include <stdio.h>
main()
{
int R, d;
{
int R, d;
float s;
printf("请输入圆的半径");
scanf("%d",&R);
d=2*R;
c=2*3.14159*R;
printf("d=%d,c=%f\n",d,c);
}
4、参考答案:
printf("请输入圆的半径");
scanf("%d",&R);
d=2*R;
c=2*3.14159*R;
printf("d=%d,c=%f\n",d,c);
}
4、参考答案:
#include <stdio.h>
void main()
{
int h, f, x, y; /* x为鸡的数量,y为兔的数量 */
printf("请输入鸡兔的总头数h,总脚数 f:");
scanf("%d%d", &h, &f);
x=(4*h-f)/2;
void main()
{
int h, f, x, y; /* x为鸡的数量,y为兔的数量 */
printf("请输入鸡兔的总头数h,总脚数 f:");
scanf("%d%d", &h, &f);
x=(4*h-f)/2;
y=(f-2*h)/2;
printf("笼中有鸡%d 只,有兔%d只。\n", x, y);
}
第四章 习题答案
printf("笼中有鸡%d 只,有兔%d只。\n", x, y);
}
第四章 习题答案
一、选择题
CDDDD CDBBC
二、填空题
1、&&, || , !, ! , | |
2、(y%2 0)
2、(y%2 0)
3、1
4、(a+b>c&&a+c>b&&b+c>a)
5、2 3 3 scanf输入整型数组
6、7
三、编程题
1、参考答案:
#include <stdio.h>
void main()
{ int x;
scanf( "%d",&x);
if (x%5 0 && x%7 0)
printf("yes\n");
{ int x;
scanf( "%d",&x);
if (x%5 0 && x%7 0)
printf("yes\n");
else
printf("no\n");
}
2、参考答案:
}
2、参考答案:
#include <stdio.h>
void main( )
{ int a, b, c, max ;
printf ("请输入三个整数:%%d%%d%%d\n");
scanf( "%d%d%d", &a, &b, &c );
if ( a>=b )
if ( a>=c ) max=a;
else max=c;
{ int a, b, c, max ;
printf ("请输入三个整数:%%d%%d%%d\n");
scanf( "%d%d%d", &a, &b, &c );
if ( a>=b )
if ( a>=c ) max=a;
else max=c;
else
if ( b>=c ) max=b;
else max=c;
printf ("\n 最大数为:%d\n",max );
}
3、参考答案:
else max=c;
printf ("\n 最大数为:%d\n",max );
}
3、参考答案:
#include <stdio.h>
void main ( )
{
float x , y ;
printf( "请输入x 的值:" );
scanf( "%f", &x ) ;
if (x<1) y=1;
else if (x<10)
y=2*x-1;
{
float x , y ;
printf( "请输入x 的值:" );
scanf( "%f", &x ) ;
if (x<1) y=1;
else if (x<10)
y=2*x-1;
else
y=3*x-11;
printf("y = %.2f\n", y );
}
printf("y = %.2f\n", y );
}
4、参考答案:
#include <stdio.h>
void main( )
{
int year;
float money,rate,total; /* money:本金 rate:月利率 total:本利合计
*/
printf("Input money and year =?");
scanf("%f%d", &money, &year); /* 输入本金和存款年限 */
if(year 1) rate=0.00315; /* 根据年限确定利率 */
else if(year 2) rate=0.00330;
else if(year 3) rate=0.00345;
else if(year 5) rate=0.00375;
else if(year 8) rate=0.00420;
else rate=0.0;
total=money + money * rate * 12 * year; /* 计算到期的本利合计 */
{
int year;
float money,rate,total; /* money:本金 rate:月利率 total:本利合计
*/
printf("Input money and year =?");
scanf("%f%d", &money, &year); /* 输入本金和存款年限 */
if(year 1) rate=0.00315; /* 根据年限确定利率 */
else if(year 2) rate=0.00330;
else if(year 3) rate=0.00345;
else if(year 5) rate=0.00375;
else if(year 8) rate=0.00420;
else rate=0.0;
total=money + money * rate * 12 * year; /* 计算到期的本利合计 */
printf(" Total = %.2f\n", total);
}
第五章 习题答案
}
第五章 习题答案
一、选择题
1~5: ACCBA
6~10:ACDCB
二、填空题
1、(1) i<=9 或 i<10 (2) j%3!=0
2、7
3、(1) ch=ch+1、(2) printf("\n")
三、编程题
1、参考答案:
#include <stdio.h>
void main( )
{ int i=2;
long p=1;
{ int i=2;
long p=1;
do
{ p=p*i;
i=i+2;
} while (i<10);
printf("2*4*6*8=%ld\n",p);
}
2、参考答案:
i=i+2;
} while (i<10);
printf("2*4*6*8=%ld\n",p);
}
2、参考答案:
#include <stdio.h>
void main( )
{int n=0;
char c;
c=getchar();
while(c!='\n' )
{ if((c>='a'&&c<='z')|| (c>='A'&&c<='Z')) n++;
c=getchar();
}
printf("%d\n",n);
}
3、参考答案:
{int n=0;
char c;
c=getchar();
while(c!='\n' )
{ if((c>='a'&&c<='z')|| (c>='A'&&c<='Z')) n++;
c=getchar();
}
printf("%d\n",n);
}
3、参考答案:
#include <stdio.h>
void main()
{int a,max;
scanf("%d",&a);
{int a,max;
scanf("%d",&a);
max=a;
while(a!=0)
{scanf("%d",&a);
if(max<a) max=a;
}
printf("%d",max);
}
4、参考答案:
{scanf("%d",&a);
if(max<a) max=a;
}
printf("%d",max);
}
4、参考答案:
#include <stdio.h>
void main()
{
int day = 0, buy = 2;
float sum = 0.0, ave;
{
int day = 0, buy = 2;
float sum = 0.0, ave;
do
{
sum += 0.8 * buy;
day++;
buy *= 2;
}
while (buy <= 100);
ave = sum / day;
printf(“%f”, ave);
}
5、参考答案:
sum += 0.8 * buy;
day++;
buy *= 2;
}
while (buy <= 100);
ave = sum / day;
printf(“%f”, ave);
}
5、参考答案:
#include <stdio.h>
void main()
{ int f1,f2,f5,count=0;
for(f5=0; f5<=20; f5++)
{ int f1,f2,f5,count=0;
for(f5=0; f5<=20; f5++)
for(f2=0; f2<=(100-f5*5)/2;f2++)
{ f1=100-f5*5-f2*2;
if(f5*5+f2*2+f1 100)
printf("No.%2d >> 5: %4d 2: %4d 1: %4d\n",++count,f5,f2,f1);
}
printf("共有%d 种换法",count);
}
6、参考答案:
{ f1=100-f5*5-f2*2;
if(f5*5+f2*2+f1 100)
printf("No.%2d >> 5: %4d 2: %4d 1: %4d\n",++count,f5,f2,f1);
}
printf("共有%d 种换法",count);
}
6、参考答案:
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论