网站LOGO
二级教程C语言课后参考答案
第一章

【1-1】.exe【1-2】.c  .obj  .exe 【1-3】顺序,分枝(选择),循环

第二章

【2-1】B 【2-2】D【2-3】B【2-4】A【2-5】C【2-6】A【2-7】B【2-8】B

【2-9】A【2-10】C【2-11】B【2-12】B【2-13】A

【2-14】11,12【2-15】4.2,4.2【2-16】{,},定义说明,执行语句

【2-17】关键字,用户标识符【2-18】int,float,double

【2-19】float a=b=1; 【2-20】存贮单元【2-21】3.5

【2-22】a*b/c,a/c*b,b/c*a【2-23】把10赋予变量s【2-24】bit,0/1

【2-25】8,127,01111111,-128,10000000(补码) 

【2-26】32767,-32768,1111111111111111,1000000000000000【2-27】8,10,16

【2-28-1】(错误)

#include  stdio.h;

main() / * main function * /

  float r,s; /*/*r is radius*/,/* s is area of circular */*/

  r=5.0;

  s=3.14159*r*r;

  printf("%f\n",s)

【2-28-2】(正确)

#include  stdio.h;

main() /* main function */

  {float r,s; /* r is radius, s is area of circular */

  r=5.0;

  s=3.14159*r*r;

  printf("%f\n",s);

  }

【2-29-1】(错误)

#include stdio.h

main   /* main function */

{ float a,b,c,v; /* a,b,c are sides, v is volume of cube */

  a=2.0; b=3.0; c=4.0

  v=a*b*c;

  printf("%f\n",v)

}

【2-29-2】(正确)

#include <stdio.h>

main()   /* main function */

{ float a,b,c,v; /* a,b,c are sides, v is volume of cube */

  a=2.0; b=3.0; c=4.0;

  v=a*b*c;

  printf("%f\n",v);

}

第三章

【3-1】C 【3-2】C 【3-3】D 【3-4】C 【3-5】D 【3-6】B 【3-7】C 

【3-8】D 【3-9】A 【3-10】B 【3-11】C 【3-12】D 【3-13】D

【3-14】C 【3-15】C 【3-16】C 【3-17】C 【3-18】A 【3-19】C

【3-20】B 【3-21】(1)-200 2500(2)i=-200, j=2500(3)i=-200//(换行)j=2500

【3-22】12,0,0【3-23】一条语句,;【3-24】; 

【3-25】100 25.81 1.89234,100//25.81//1.89234,100//25.81 1.89234

【3-26】x=127,x=   127,x=   177,x=   7f,x=  127

【3-27】x=127,x=127   ,x=$127   ,x=$000127,x=%06d

【3-28】a=513.789215,a=  513.79,a=  513.78921500,a=  513.78921500

【3-29-1】(错误)

main

{ double a,b,c,s,v;

  printf(input a,b,c:\n);

  scanf("%d %d %d",a,b,c);

  s=a*b;

  v=a*b*c;

  printf("%d %d %d",a,b,c);

  printf("s=%f\n",s,"v=%d\n",v);

}

【3-29-2】(正确)

main()

{ float a,b,c,s,v;

  printf("input a,b,c:");

  scanf("%f %f %f:",&a,&b,&c);

  s=a*b;

  v=a*b*c;

  printf("a=%f,b=%f,c=%f\n",a,b,c);

  printf("s=%f,v=%f\n",s,v);

}

【3-30】

main()

{ int h,m;

 h=560/60;

 m=560%60;

 printf("%dh:%dm",h,m);

 getch();

}

【3-31】

main()

{ int m,n;

 printf("input m & n:");

 scanf("%d%d",&m,&n);

 printf("\n%d,%d\n",m/n,m%n);

 getch();

}

 

 

【3-32】

main()

{ double x,y,z,s;

  printf("input x,y,z: ");

  scanf("%lf%lf%lf",&x,&y,&z);

  s=(x+y+z)/3.0;

  printf("\nAverage=%6.1lf\n",s);

  getch();

}

【3-33】

main()

{ int a,b,c,t;

  printf("Input a,b,c: ");

  scanf("%d%d%d",&a,&b,&c);

  t=c;

  c=b;

  b=a;

  a=t;

  printf("\na,b,c=%d,%d,%d\n",a,b,c);

  getch();

}

 

第四章

【4-1】A【4-2】A【4-3】A【4-4】D【4-5】C【4-6】A【4-7】B【4-8】A

【4-9】D【4-10】A【4-11】非零,零【4-12】<,>,<=,>=  ==,!=

【4-13】!,&&,|| 【4-14】!,关系运算符,&&,|| 【4-15】! 

【4-16】(A)a==b||a<c(B)fabs(x)>4【4-17】1【4-18】x<=0,1【4-19】3,2,2

【4-20】*#

【4-21】

main()

{ int a,m;

  printf("input a: ");

  scanf("%d",&a);

  switch(a/10)

   { case 0:

     case 1:

     case 2: m=1 ;break;

     case 3: m=2 ;break;

     case 4: m=3 ;break;

     case 5: m=4 ;break;

     default: m=5;

    }

   printf("a,m=%d, %d",a,m );

   getch();

}

【4-22】

main()

{ int age,y0,m0,d0,y1,m1,d1;

  printf("\ninput a stedent\' birthday (yy-mm-dd): ");

  scanf("%d-%d-%d",&y0,&m0,&d0);

  printf("\ninput today\' date (yy-mm-dd): ");

  scanf("%d-%d-%d",&y1,&m1,&d1);

  if ((m1>m0)||(m1==m0)&&(d1>=d0)) age=y1-y0;

  else age=y1-y0-1;

  printf("\nThe student\' age is %d",age);

  getch();

}

【4-23】

main()

{ int m;

  printf("\ninput a integer: ");

  scanf("%d",&m);

  if (m%2==0) printf("\n%d is event.",m);

  else printf("\n%d is ord.",m);

  getch();

}

【4-24】

main()

{ int a,b,c,max;

  printf("\ninput a,b,c: ");

  scanf("%d%d%d",&a,&b,&c);

  max=a;

  if (b>max) max=b;

  if (c>max) max=c;

  printf("max is %d",max);

  getch();

}

【4-25-1】

main()

{ int x,y;

  printf("\ninput x: ");

  scanf("%d",&x);

  if((x>-5)&&(x<0)) y=x;

  if (x==0) y=x-1;

  if ((x>0)&&(x<10)) y=x+1;

  printf("\nx is %d , y is %d",x,y);

  getch();

}

【4-25-2】

main()

{ int x,y;

  printf("\ninput x: ");

  scanf("%d",&x);

  if((x>-5)&&(x<10))

    { if (x<0) y=x;

      if (x==0) y=x-1;

      if (x>0) y=x+1;

      printf("\nx is %d , y is %d",x,y);

    }

  else printf("input x is error ! %c",'\007');

  getch();

}

【4-25-3】

main()

{ int x,y;

  printf("\ninput x: ");

  scanf("%d",&x);

  if ((x>-5)&&(x<0)) y=x;

    else  if (x==0)  y=x-1;

      else if ((x>0)&&(x<10)) y=x+1;

      printf("\nx is %d , y is %d",x,y);

  getch();

}

【4-25-4】

main()

{ int x,y;

  printf("\ninput x: ");

  scanf("%d",&x);

  switch(x)

  { case -4:

    case -3:

    case -2:

    case -1: y=x;break;

    case 0 : y=x-1;break;

    case 1 :

    case 2 :

    case 3 :

    case 4 :

    case 5 :

    case 6 :

    case 7 :

    case 8 :

    case 9 : y=x+1;break;

    default : printf("Input x error ! %c",7);

   }

   printf("\nx is %d , y is %d",x,y);

   getch();

}

 

第五章

【5-1】D【5-2】C【5-3】B【5-4】C【5-5】C【5-6】B【5-7】D【5-8】A

【5-9】D【5-10】D【5-11】5,4,6【5-12】死循环【5-13】-1【5-14】11

【5-15】d=1,k++,k<n【5-16】x>=0,x<amin

【5-17】

main()

{ int i,s=1,k=-1;

  for (i=1;i<=50;i++)

  { s=s+k*(2*i+1);

    k=-k;

  }

 printf("s=%d",s);

 getch();

}

【5-18-1】

main()

{ int i=1;

  double e=1.0,s=1.0;

  for(i=1;i<=50;i++)

  {s=s*i;

   e=e+1/s;

  }

 printf("e=%lf",e);

 getch();

}

 

【5-18-2】

main()

{ int i=1;

  float e=1.0,s=1.0;

  while (1/s>=1e-04)  /* 8 times */

  {s=s*i;

   i++;

   e=e+1/s;

  }

 printf("e=%10.6f",e);

 getch();

}

【5-19】

main()

{ int y,k=0;

  for(y=1000;y<=2000;y++)

   { if (y%4==0&&y%100!=0||y%400==0) {printf("%10d",y);k++;}

     if (k%3==0) printf("\n");

   }

  getch();

}

【5-20】

#include <stdio.h>

main()

{int i,j,n;

 printf("Input n (1--10):");

 do scanf("%d",&n);

 while (n<1||n>10);

for (i=1;i<=n;i++)

 {for (j=1;j<=40-i;j++)

   printf(" ");

  for (j=1;j<=2*i-1;j++)

   printf("*");

  printf("\n");

 }

for (i=n+1;i<=2*n-1;i++)

 { for (j=1;j<=40-2*n+i;j++)

      printf(" ");

   for (j=1;j<=4*n-1-2*i;j++)

      printf("*");

   printf("\n");

  }

getch();

}

 

第六章

【6-1】B【6-2】D【6-3】A【6-4】A【6-5】B【6-6】D【6-7】D【6-8】B

【6-9】A【6-10】A【6-11】C【6-12】26【6-13】1【6-14】ctype.h

【6-15】1 【6-16】10A20B30C40D【6-17】7.29 101.298AB

【6-18】A7.29B101.298【6-19】A   B   C   

【6-20】

#include <stdio.h>

main()

{ int k=0; char ch;

  while((ch=getchar())!=10)

  { k++;

    printf("%4c%4d",ch,ch);

    if(k%3==0) printf("\n");

  }

getch();

}

【6-21】

#include <stdio.h>

main()

{ long k=0; char ch;

  while((ch=getchar())!=EOF)

  { if (ch>='0'&&ch<='9')

     { ch=ch-'0';

     k=k*10+ch;

     }

   }

  printf("%ld",k);

getch();

}

【6-22】

#include <stdio.h>

main()

{ int flag,k=0; char ch;

  while((ch=getchar())!=EOF)

  { if (ch==10) { k++; flag=0; }

    else flag=1;

   }

  if (flag==1) k++;

  printf("\n The line number is %d\n",k);

getch();

}

【6-23】

#include <stdio.h>

main()

{ int k=0; char ch;

  while((ch=getchar())!=10)

   if (ch>='a'&&ch<='z') k++;

   printf("\n The lower letter number is %d\n",k);

getch();

}

【6-24】

#include <stdio.h>

main()

{ int i,j,n;

  printf("Input line number : ");

  scanf("%d",&n);

  for(i=1;i<=n;i++)

   { for (j=1;j<=40-i;j++)

       printf(" ");

     for(j=1;j<=2*i-1;j++)

       printf("%c",64+i);

     printf("\n");

   }

getch();

}

 

第七章

【7-1】C【7-2】C【7-3】B【7-4】C【7-5】A【7-6】D【7-7】A【7-8】12

【7-9】9.000000【7-10】4【7-11】n=1,s【7-12】<=y,z*x【7-13】1,s*i,0,f(k)

【7-14-1】(错误)

main()

{int m;

 printf("Input a number: ");

 scanf("%d",&m);

 m=fun(m);

 if (m==1)

     printf("\nThis number is a primer !\n");

 else

     printf("\nThis number is not a primer !\n");

getch();

}

 

fun(int n)

{ int k,yes;

  for (k=2;k<=n/2;k++)

    if (n%k==0) yes=0;

    else yes=1;

  return yes;

}

【7-14-2】(正确)

main()

{int m;

 printf("Input a number: ");

 scanf("%d",&m);

 m=fun(m);

 if (m==1)

     printf("\nThis number is a primer !\n");

 else

     printf("\nThis number is not a primer !\n");

getch();

}

 

fun(int n)

{ int k,yes=1;

  for (k=2;k<=n/2;k++)

    if (n%k==0) yes=0;

  return yes;

}

【7-15】

main()

{int a,b;

 printf("Input a & b:");

 scanf("%d%d",&a,&b);

 printf("\n%d%%%d=%d",a,b,mymod(a,b));

 getch();

}

mymod(int a, int b)

{int z;

 z=a%b;

 return z;

 }

【7-16】

float fun(int n)

{return (1.0/n);}

 

main()

{int i,n,k=1;

 float s=0.0;

 printf("Input n:");

 scanf("%d",&n);

 for(i=1;i<=n;i++)

 {s+=k*fun(i);

  k=-k;

 }

 printf("\ns=%8.6f",s);

 getch();

}

【7-17】

float f(int m)

{ float t=1.0;

  int i;

  for (i=2;i<=m;i++)

    t-=1.0/(i*i);

  return t;

}

main()

{int n;

 printf("Input n:");

 scanf("%d",&n);

 printf("\nt=%8.6f",f(n));

 getch();

}

【7-18】

#include <math.h>

float f(float x)

{ float z;

  z=x*x-5*x+4;

  return z;

}

main()

{float x,y1,y2,y3;

 printf("Input x: ");

 scanf("%f",&x);

 y1=f(2);

 y2=f(x+15);

 y3=f(sin(x));

 printf("y1=%10.4f\n",y1);

 printf("y2=%10.4f\n",y2);

 printf("y3=%10.4f\n",y3);

 printf("\n**** END ****");

 getch();

}

第八章

【8-1】A【8-2】B【8-3】B【8-4】C【8-5】B【8-6】B【8-7】C【8-8】D

【8-9】B【8-10】C【8-11】C【8-12】C【8-13】110【8-14】7 1

【8-15】char *p=ch;,p=&ch;,scanf(“%c”,p);,p=’a’;,printf(“%c”,p);

【8-16】s=p+3;,s-=2,50,*(s+1),2,10 20 30 40 50

【8-17-1】

fun(x,y)

int *x,*y;

{int z1,z2;

 z1=*x+*y;

 z2=*x-*y;

 *x=z1; *y=z2;

}

main()

{int *a,*b,A,B;

 a=&A,b=&B;

 printf("input two numbers: ");

 scanf("%d%d",a,b);

 printf("a,b=%d,%d\n",*a,*b);

 printf("before call function:\n");

 printf("a=%d    b=%d\n",*a,*b);

 fun(a,b);

 printf("after call function:\n");

  printf("a=%d    b=%d\n",*a,*b);

  getch();

}

【8-17-2】

fun(x,y)

float *x,*y;

{float z1,z2;

 z1=*x+*y;

 z2=*x-*y;

 *x=z1; *y=z2;

}

main()

{float *a,*b,A,B;

 a=&A;b=&B;

 printf("input two real numbers: ");

 scanf("%f%f",a,b);

 printf("a,b=%f, %f\n",*a,*b);

 printf("before call function:\n");

 printf("a=%f    b=%f\n",*a,*b);

 fun(a,b);

 printf("after call function:\n");

  printf("a=%f    b=%f\n",*a,*b);

  getch();

}

【8-18】

fun(int *a,int *b,int *c)

{ int max,min;

  max=*a;min=*a;

  if (*b>*a) max=*b;

  if (*b<*a) min=*b;

  if (*c>max) max=*c;

  if (*c<min) min=*c;

  *a=max;*c=min;

}

main()

{int a,b,c;

 printf("Input a,b,c: ");

 scanf("%d%d%d",&a,&b,&c);

 printf("before call function:\n");

 printf("a=%d    b=%d   c=%d\n",a,b,c);

 fun(&a,&b,&c);

 printf("after call function:\n");

 printf("max=%d   min=%d\n",a,c);

 getch();

}

  相关文章
 
热点文章
 
热点下载
Copyright © 2007 KaoEase.Com, All Rights Reserved