整理C语言程序设计答案曹计昌.docx

上传人:b****6 文档编号:12884964 上传时间:2023-06-08 格式:DOCX 页数:45 大小:22.79KB
下载 相关 举报
整理C语言程序设计答案曹计昌.docx_第1页
第1页 / 共45页
整理C语言程序设计答案曹计昌.docx_第2页
第2页 / 共45页
整理C语言程序设计答案曹计昌.docx_第3页
第3页 / 共45页
整理C语言程序设计答案曹计昌.docx_第4页
第4页 / 共45页
整理C语言程序设计答案曹计昌.docx_第5页
第5页 / 共45页
整理C语言程序设计答案曹计昌.docx_第6页
第6页 / 共45页
整理C语言程序设计答案曹计昌.docx_第7页
第7页 / 共45页
整理C语言程序设计答案曹计昌.docx_第8页
第8页 / 共45页
整理C语言程序设计答案曹计昌.docx_第9页
第9页 / 共45页
整理C语言程序设计答案曹计昌.docx_第10页
第10页 / 共45页
整理C语言程序设计答案曹计昌.docx_第11页
第11页 / 共45页
整理C语言程序设计答案曹计昌.docx_第12页
第12页 / 共45页
整理C语言程序设计答案曹计昌.docx_第13页
第13页 / 共45页
整理C语言程序设计答案曹计昌.docx_第14页
第14页 / 共45页
整理C语言程序设计答案曹计昌.docx_第15页
第15页 / 共45页
整理C语言程序设计答案曹计昌.docx_第16页
第16页 / 共45页
整理C语言程序设计答案曹计昌.docx_第17页
第17页 / 共45页
整理C语言程序设计答案曹计昌.docx_第18页
第18页 / 共45页
整理C语言程序设计答案曹计昌.docx_第19页
第19页 / 共45页
整理C语言程序设计答案曹计昌.docx_第20页
第20页 / 共45页
亲,该文档总共45页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

整理C语言程序设计答案曹计昌.docx

《整理C语言程序设计答案曹计昌.docx》由会员分享,可在线阅读,更多相关《整理C语言程序设计答案曹计昌.docx(45页珍藏版)》请在冰点文库上搜索。

整理C语言程序设计答案曹计昌.docx

整理C语言程序设计答案曹计昌

第一章习题

原码:

对于一个二进制数X,若是规定其最高位为符号位,其余列位为该数的绝对值,而且规定符号位值为0表示正,为1表示负,采用这种方式的二进制编码称为该二进制数X的原码。

补码:

正数的补码等于正数的原码,负数的补码为其原码除符号位不动外,其余列位变反再加1所得。

反码:

对于正数而言,反码与原码相同;对于负数而言,反码符号位的概念与原码相同,但需要将对应原码的数值位按位变反。

和:

差:

00010000

和01073

  差-0337

和0x1AABA

差-0x5320

(251)10=()2=(373)8=(FB)16

在16位机中,[157]补=00000000

            [-153]补=111

157-153=157+(-153)

=(00000000)2+(111)2=(0000000000000100)2=(4)10

算法设计:

用变量s存储累加和,k表示计数

描述为:

(1)概念变量s,k。

(2)s清零,k赋初值1。

(3)判断k<101?

若是是,顺序执行(4);不然转步骤(5);

(4)k加到累加和变量s中,k加1;转步骤(3)。

(5)输出累加和s。

(6)结束。

 

 

 

开始

结束

ints=0,k=1;

k<101?

s=s+k;

k=k+1;

输出s

N

Y

 

 

 

第二章习题

(1)x,++,+,y

(2)-,0xabL

(3)+12L

(4)”String+”FOO””

(5)x,*,*,2

(6)”X?

?

/”

(7)a,?

b

(8)x,--,+=,y

(9)intx,=,+,10

(10)”String”,“FOO”

 

不是表识符的如下:

4th首字母为数字 sizeof关键字 

x*y*不是字母、数字、下划线

temp-2-不是字母、数字、下划线

isn’t ’不是字母、数字、下划线

enum关键字

 

合法常数:

.12                   浮点型常量

2L  33333   0377UL0x9cfU 整型常量

“a” “”   字符串常量

‘45’             ‘’        ‘a’ 字符常量

 

非法常数:

‘‘’必需用转义序列

0x1ag十六进制没有g

E20没有尾数部份

‘18’      要用八进制数

‘xa’格式错误,能够是’xa’

“3’4””   需要转义序列

‘”’  需要转义序列

 

(1)inta,b=5;

(2)doubleh;

(3)intx=;会被截取。

(4)constlongy=1;必需赋初值

(5)floata=*g; g没有概念。

(6)inta=b=2;在turboC中编译犯错:

未概念的符号’b’在main函数中。

 

 

(1)4

(2)0

(3)1

(4)6

(5)8

(6)0

(7)

(8)1

(9)108

(10)0

 

 答案不肯定

(1)a==b==c c未概念

(2)正确

(3)正确

(4)正确

(5)a*++-b  表达式缺值

(6)a||b^i  ^运算的操作数必需是整型,而i不是

(7)i*j%a %运算的操作数必需是整型,而a不是

(8)正确

(9)正确

(10)int(a+b) 应该改成(int)(a+b)

 

(1)0

(2)-2

(3)65535

(4)5

(5)60

(6)113

(7)-2

(8)-1

(9)65532

(10)3

 

unsignedlongencrypt(unsignedlongx)

{

  unsignedlongx0,x1,x2,x3,x4,x5,x6,x7;

  x0=(x&0x0000000F)<<8;

  x1=(x&0x000000F0);

  x2=(x&0x00000F00)<<8;

  x3=(x&0x0000F000);

  x4=(x&0x000F0000)<<8;

  x5=(x&0x00F00000);

  x6=(x&0x0F000000)>>24;

  x7=(x&0xF0000000);

  return(x0|x1|x2|x3|x4|x5|x6|x7);

}

 

#include<>

voidmain()

{

 

unsignedlongin;

unsignedlonga,b,c,d;

scanf("%ld",&in);

d.%d.%d",a,b,c,d);

}

 

((k>>8)&0xFF00)|((p&0x00FF)<<8)

 

max=a>b?

a>c?

a:

c:

b>c?

b:

c;

max=a>b?

((a>c)?

a:

c):

((b>c)?

b:

c);

 

X=y>>n

 

(c>=’0’&&c<=’9’)?

c–‘0’:

c

 

(a%3==0)&&(a%10==5)?

a:

0;

第三章习题

函数原型是指对函数的名称、返回值类型、参数的数量和参数类型的说明。

其规定了挪用该函数的语法格式,即挪用形式。

putchar函数的原型为:

intputchar(intc);

puts函数的原型为:

intputs(constchar*s);

printf函数的原型为:

intprintf(constchar*format,…);

getchar函数的原型为:

intgetchar_r(void);

gets函数的原型为:

char*gets_r(char*s);

scanf函数的原型为:

intscanf(constchar*format,…);

不同点:

①puts为非格式输出函数,printf为格式输出函数;

           ②puts函数的参数类型和数量必然(一个字符串),printf函数的参数类型和数量不固定;

           ③puts函数输出后会自动换行,printf函数没有这一功能。

   相同点:

①二者都向标准设备输出;

           ②二者返回值类型都为int。

x1=-1,177777,ffff,65535

   x2=-3,177775,fffd,65533

   y1=,  ,, (注意对齐)

   y2=,+02,

   x1(%4d)= -1

⑴%c;⑵%c;⑶%f;⑷%f;⑸%lu;⑹%d;⑺%d;⑻%d;⑼%f;⑽%Lf

⑴错误,运行提示为divideerror

   ⑵正确,结果为b

   ⑶正确,结果为        *

   ⑷正确

   ⑸正确,但无法正常从结果中退出

   ⑹正确

   ⑺正确,结果为82,63

   ⑻编译错误,提示cannotmodifyaconstobject

   ⑼正确

   ⑽正确

   -6

   177601

   123

   -2    0

#include<>

voidmain()

{

      charc;

      c=getchar_r();

      if((c>='0'&&c<='9')||(c>='A'&&c<='F')||(c>='a'&&c<='f'))

      {

             if((c>='0'&&c<='9'))

             {

                    printf("%dn",c-'0');

             }

             elseif((c>='A'&&c<='F'))

             {

             printf("%dn",c-'A'+10);

             }

             else

             printf("%dn",c-'a'+10);

      }

      else

             putchar(c);

}

 

#include<>

voidmain()

{

      shortnum,high,low;

      printf("Pleaseinputashortnumber:

n");

  scanf("%hd",&num);

  low=0x00ff#

  high=0x00ff&(num>>8);

  printf("Thehighbyteis:

%cn",high);

  printf("Thelowbyteis:

%cn",low);

   }

 

#include""

 

intmain(intargc,char*argv[])

{

      unsignedshortintx;

      unsignedshortinthigh,low;

      printf("inputainteger:

n");

      scanf("%d",&x);

      high=(x>>12)&0x000f;

      low=(x<<12)&0xf000;

      x=x&0x0ff0;

      x=x|high|low;

      printf("%dn",x);

      return0;

}

 

 

#include<>

voidmain()

{

unsignedshortintx,m,n;

unsignedshortintresult;

scanf("%hu%hu%hu",&x,&m,&n);

result=(x>>(m-n+1))<<(15-n+1);

printf("%hun",result);

 

}

 

#include<>

voidmain()

{

      floatf,c;

      scanf("%f",&f);

      c=(5*(f-32))/9;

      printf("%.0f(F)=%.2f(C)n",f,c);

}

#include<>

voidmain()

{

intf;     

floatc;

      scanf("%d",&f);

      c=(5*(f-32))/9;

      printf("%d(F)=%.2f(C)n",f,c);

}

 

#include<>

#definePI

intmain(intargc,char*argv[])

{

      doubler,h;

      doubles,v;

      printf("Pleaseinputtherandh.");

      scanf("%lf,%lf",&r,&h);

      s=2*PI*r*h+2*PI*r*r;

      v=PI*r*r*h;

      printf("sis%lf,vis%lf",s,v);

      return0;

}

 

#include""

 

intmain(intargc,char*argv[])

{

      

      chara[4]="编";

      printf("机内码:

%x%xtn",a[0]&0xff,a[1]&0xff);

      printf("区位码:

%xtn",a[0]&0xff<<8+a[1]&0xff-0x2020-0x8080);

      printf("国际码:

%xtn",a[0]&0xff<<8+a[1]&0xff-0x8080);

      return0;

}

第四章习题

#include<>

voidmain(void)

{

floata,b,c;

printf("PleaseenterthescoreofA:

n");

scanf("%f",&a);

printf("PleaseenterthescoreofB:

n");

scanf("%f",&b);

printf("PleaseenterthescoreofC:

n");

scanf("%f",&c);

if((a-b)*(a-c)<0)

 printf("Agetsthescore%.1f",a);

if((b-a)*(b-c)<0)

 printf("Bgetsthescore%.1f",b);

if((c-a)*(c-b)<0)

 printf("Cgetsthescore%.1f",c);

}

#include<>

intmdays(inty,intm)

{

      if(m==2)return(y%4==0&&(y%100==0||y%400==0))?

29:

28;

      elseif(m==4||m==6||m==9||m==11)return30;

      elsereturn31;

}

 

main()

{

      inty,m,d,days;

      printf("Enteryear:

");

      scanf("%d",&y);

      printf("Entermonth:

");

      scanf("%d",&m);

      printf("Enterday:

");

      scanf("%d",&d);

      days=d;

      while(m>1){days+=mdays(y,m-1);m--;}

      printf("%dn",days);

}

 if方式:

#include""

#include<>

intmain(intargc,char*argv[])

{

      floatx=0;

      printf("inputthesalaryn");

      scanf("%f",&x);

      if(x<0)

             printf("wrongn");

      elseif(x>0&&x<1000)

                    printf("0n");

                    elseif(x<2000)

                           printf("%fn",x*;

                           elseif(x<3000)

                                  printf("%fn",x*;

                                  elseif(x<4000)

                                         printf("%fn",x*;

                                         elseif(x<5000)

                                                printf("%fn",x*;

                                                else

                                                       printf("%fn",x*;

      return0;

}

 

Case方式:

 

#include""

#include<>

intmain(intargc,char*argv[])

{

      floatx;

      printf("inputthesalaryn");

      scanf("%f",&x);

      intxCase=0;

      xCase=(int)(x/;

      switch(xCase)

      {

      case0:

                    printf("0n");

                    break;

      case1:

                    printf("%fn",x*;

                    break;

      case2:

                    printf("%fn",x*;

                    break;

      case3:

                    printf("%fn",x*;

                    break;

      case4:

                    printf("%fn",x*;

                    break;

      default:

                    printf("%fn",x*;

      }

      return0;

}

 

#include""

#include<>

intmain(intargc,char*argv[])

{

      char*sa;

      charc;

      inti=0,j=0,k=0;

      do

      {

             c=getchar_r();

             sa[i++]=c;

      }while(c!

='r');

      for(i=0;sa[i+1];i++)

      {

             for(j=i+1;sa[j];j++)

             {

                    if(sa[i]==sa[j]&&sa[j]=='')

                    {

                           for(k=j;sa[k];k++)

                                 sa[k]=sa[k+1];

                           j--;

                    }

             }

      }

      for(k=0;sa[k];k++)

             printf("%2c",sa[k]);

      return0;

}

 

#include<>

#defineEPS1e-5

voidmain()

{

      ints=1;

      floatn=,t=,pi=0;

      whilen>=EPS)

      {

             pi=pi+t;

             n=n+2;

             s=s*(-1);

             t=s/n;

      }

      pi=pi*4;

      printf("pi=%",pi);

}

 

#include<>

intmain()

{

      inta,b,num1,num2,temp;

      printf("Inputa&b:

");

      scanf("%d%d",&num1,&num2);

      if(num1>num2)

      {

             temp=num1;num1=num2;num2=temp;

      }

      a=num1;b=num2;

      while(b!

=0)

      {

             temp=a%b;

             a=b;

             b=temp;

      }

      printf("TheGCDof%dand%dis:

%dn",num1,num2,a);

      printf("TheLCMofthemis:

%dn",num1*num2/a);

}

#include""

#include<>

intPrimes(intx);fn",r,v[r]);

}

return0;

}

第七章习题

#include<>

#include<>

#defineg10

voidmain()

{

char*buffer;

intgdriver=DETECT,gmode,i,size;

initgraph(&gdriver,&gmode,"c:

\tc\bgi");

setbkcolor(BLUE);

setcolor(RED);

setlinestyle(0,0,1);

setfillstyle(1,5);

circle(200,250,RED);

size=imagesize(200,250,200,300);

buffer=malloc(size);

getimage_r(200,250,200,300,buffer);

for(i=0;i<=10;i++)

putimage(200,250+g*i*i/2,buffer,COPY_PUT);

getch_r();

closegraph();

}

 

#include<>

#defineRAND_MAX32767

#defineRAND  100

intRandomInteger(intlow,inthigh) 

{

   intk;

   doubled;

   d=(double)rand()/((double)RAND_MAX+1);

   k=(int)(d*(high-low+1));

 

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 求职职场 > 简历

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2