c语言C程序设计第四版谭浩强课后习题答案第8章Word格式.docx

上传人:b****3 文档编号:7638468 上传时间:2023-05-08 格式:DOCX 页数:32 大小:20.90KB
下载 相关 举报
c语言C程序设计第四版谭浩强课后习题答案第8章Word格式.docx_第1页
第1页 / 共32页
c语言C程序设计第四版谭浩强课后习题答案第8章Word格式.docx_第2页
第2页 / 共32页
c语言C程序设计第四版谭浩强课后习题答案第8章Word格式.docx_第3页
第3页 / 共32页
c语言C程序设计第四版谭浩强课后习题答案第8章Word格式.docx_第4页
第4页 / 共32页
c语言C程序设计第四版谭浩强课后习题答案第8章Word格式.docx_第5页
第5页 / 共32页
c语言C程序设计第四版谭浩强课后习题答案第8章Word格式.docx_第6页
第6页 / 共32页
c语言C程序设计第四版谭浩强课后习题答案第8章Word格式.docx_第7页
第7页 / 共32页
c语言C程序设计第四版谭浩强课后习题答案第8章Word格式.docx_第8页
第8页 / 共32页
c语言C程序设计第四版谭浩强课后习题答案第8章Word格式.docx_第9页
第9页 / 共32页
c语言C程序设计第四版谭浩强课后习题答案第8章Word格式.docx_第10页
第10页 / 共32页
c语言C程序设计第四版谭浩强课后习题答案第8章Word格式.docx_第11页
第11页 / 共32页
c语言C程序设计第四版谭浩强课后习题答案第8章Word格式.docx_第12页
第12页 / 共32页
c语言C程序设计第四版谭浩强课后习题答案第8章Word格式.docx_第13页
第13页 / 共32页
c语言C程序设计第四版谭浩强课后习题答案第8章Word格式.docx_第14页
第14页 / 共32页
c语言C程序设计第四版谭浩强课后习题答案第8章Word格式.docx_第15页
第15页 / 共32页
c语言C程序设计第四版谭浩强课后习题答案第8章Word格式.docx_第16页
第16页 / 共32页
c语言C程序设计第四版谭浩强课后习题答案第8章Word格式.docx_第17页
第17页 / 共32页
c语言C程序设计第四版谭浩强课后习题答案第8章Word格式.docx_第18页
第18页 / 共32页
c语言C程序设计第四版谭浩强课后习题答案第8章Word格式.docx_第19页
第19页 / 共32页
c语言C程序设计第四版谭浩强课后习题答案第8章Word格式.docx_第20页
第20页 / 共32页
亲,该文档总共32页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

c语言C程序设计第四版谭浩强课后习题答案第8章Word格式.docx

《c语言C程序设计第四版谭浩强课后习题答案第8章Word格式.docx》由会员分享,可在线阅读,更多相关《c语言C程序设计第四版谭浩强课后习题答案第8章Word格式.docx(32页珍藏版)》请在冰点文库上搜索。

c语言C程序设计第四版谭浩强课后习题答案第8章Word格式.docx

inputthreeintegern1,n2,n3:

"

);

scanf("

%d,%d,%d"

&

n1,&

n2,&

n3);

p1=&

n1;

p2=&

n2;

p3=&

n3;

if(n1>

n2)swap(p1,p2);

n3)swap(p1,p3);

if(n2>

n3)swap(p2,p3);

Now,theorderis:

%d,%d,%d\n"

n1,n2,n3);

return0;

}

voidswap(int*p1,int*p2)

{intp;

p=*p1;

*p1=*p2;

*p2=p;

string.h>

{voidswap(char*,char*);

charstr1[20],str2[20],str3[20];

inputthreeline:

\n"

gets(str1);

gets(str2);

gets(str3);

if(strcmp(str1,str2)>

0)swap(str1,str2);

if(strcmp(str1,str3)>

0)swap(str1,str3);

if(strcmp(str2,str3)>

0)swap(str2,str3);

%s\n%s\n%s\n"

str1,str2,str3);

voidswap(char*p1,char*p2)

{charp[20];

strcpy(p,p1);

strcpy(p1,p2);

strcpy(p2,p);

8-3

{voidinput(int*);

voidmax_min_value(int*);

voidoutput(int*);

intnumber[10];

input(number);

max_min_value(number);

output(number);

voidinput(int*number)

{inti;

input10numbers:

for(i=0;

i<

10;

i++)

%d"

number[i]);

voidmax_min_value(int*number)

{int*max,*min,*p,temp;

max=min=number;

for(p=number+1;

p<

number+10;

p++)

if(*p>

*max)max=p;

elseif(*p<

*min)min=p;

temp=number[0];

number[0]=*min;

*min=temp;

if(max==number)max=min;

temp=number[9];

number[9]=*max;

*max=temp;

voidoutput(int*number)

{int*p;

Now,theyare:

"

for(p=number;

%d"

*p);

8-4

intmain()

{voidmove(int[20],int,int);

intnumber[20],n,m,i;

howmanynumbers?

n);

input%dnumbers:

n);

n;

howmanyplaceyouwantmove?

m);

move(number,n,m);

number[i]);

}

voidmove(intarray[20],intn,intm)

{int*p,array_end;

array_end=*(array+n-1);

for(p=array+n-1;

p>

array;

p--)

*p=*(p-1);

*array=array_end;

m--;

if(m>

0)move(array,n,m);

8-5

{inti,k,m,n,num[50],*p;

\ninputnumberofperson:

n="

p=num;

*(p+i)=i+1;

i=0;

k=0;

m=0;

while(m<

n-1)

{if(*(p+i)!

=0)k++;

if(k==3)

{*(p+i)=0;

m++;

i++;

if(i==n)i=0;

while(*p==0)p++;

ThelastoneisNO.%d\n"

8-6

{intlength(char*p);

intlen;

charstr[20];

printf("

inputstring:

scanf("

%s"

str);

len=length(str);

Thelengthofstringis%d.\n"

len);

return0;

intlength(char*p)

{intn;

n=0;

while(*p!

='

\0'

{n++;

p++;

return(n);

8-7

{voidcopystr(char*,char*,int);

intm;

charstr1[20],str2[20];

whichcharacterthatbegintocopy?

if(strlen(str1)<

m)

inputerror!

else

{copystr(str1,str2,m);

result:

%s\n"

str2);

voidcopystr(char*p1,char*p2,intm)

while(n<

m-1)

p1++;

while(*p1!

{*p2=*p1;

p2++;

*p2='

;

8-8

{intupper=0,lower=0,digit=0,space=0,other=0,i=0;

char*p,s[20];

while((s[i]=getchar())!

\n'

)i++;

p=&

s[0];

while(*p!

{if(('

A'

<

=*p)&

&

(*p<

Z'

))

++upper;

elseif(('

a'

z'

++lower;

elseif(*p=='

'

++space;

elseif((*p<

9'

)&

(*p>

0'

++digit;

++other;

uppercase:

%dlowercase:

upper,lower);

space:

%ddigit:

%dother:

%d\n"

space,digit,other);

8-9

{voidmove(int*pointer);

inta[3][3],*p,i;

inputmatrix:

3;

%d%d%d"

a[i][0],&

a[i][1],&

a[i][2]);

p=&

a[0][0];

move(p);

Now,matrix:

%d%d%d\n"

a[i][0],a[i][1],a[i][2]);

voidmove(int*pointer)

{inti,j,t;

for(j=i;

j<

j++)

{t=*(pointer+3*i+j);

*(pointer+3*i+j)=*(pointer+3*j+i);

*(pointer+3*j+i)=t;

8-10-1

{voidchange(int*p);

inta[5][5],*p,i,j;

5;

for(j=0;

a[i][j]);

change(p);

{for(j=0;

a[i][j]);

voidchange(int*p)

{inti,j,temp;

int*pmax,*pmin;

pmax=p;

pmin=p;

i++)

{if(*pmax<

*(p+5*i+j))pmax=p+5*i+j;

if(*pmin>

*(p+5*i+j))pmin=p+5*i+j;

temp=*(p+12);

*(p+12)=*pmax;

*pmax=temp;

temp=*p;

*p=*pmin;

*pmin=temp;

pmin=p+1;

if(((p+5*i+j)!

=p)&

(*pmin>

*(p+5*i+j)))pmin=p+5*i+j;

temp=*pmin;

*pmin=*(p+4);

*(p+4)=temp;

=(p+4))&

((p+5*i+j)!

=p)&

(*pmin>

*(p+5*i+j)))pmin=p+5*i+j;

*pmin=*(p+20);

*(p+20)=temp;

((p+5*i+j)!

=(p+4))&

=(p+20))&

*(p+5*i+j)))

pmin=p+5*i+j;

*pmin=*(p+24);

*(p+24)=temp;

8-10-2

voidchange(int*p)//交换函数

i++)//找最大值和最小值的地址,并赋给pmax,pmin

//将最大值与中心元素互换

//将最小值与左上角元素互换

//将a[0][1]的地址赋给pmin,从该位置开始找最小的元素

i++)//找第二最小值的地址赋给pmin

{if(i==0&

j==0)continue;

if(*pmin>

*(p+5*i+j))pmin=p+5*i+j;

//将第二最小值与右上角元素互换

i++)//找第三最小值的地址赋给pmin

{if((i==0&

j==0)||(i==0&

j==4))continue;

if(*pmin>

//将第三最小值与左下角元素互换

i++)//找第四最小值的地址赋给pmin

{if((i==0&

j==4)||(i==4&

j==0))continue;

//将第四最小值与右下角元素互换

8-11-1

{voidsort(chars[][6]);

inti;

charstr[10][6];

input10strings:

str[i]);

sort(str);

Now,thesequenceis:

voidsort(chars[10][6])

{inti,j;

char*p,temp[10];

p=temp;

9;

9-i;

if(strcmp(s[j],s[j+1])>

0)

{strcpy(p,s[j]);

strcpy(s[j],s[+j+1]);

strcpy(s[j+1],p);

8-11-2

{voidsort(char(*p)[6]);

char(*p)[6];

p=str;

sort(p);

voidsort(char(*s)[6])

chartemp[6],*t=temp;

{strcpy(t,s[j]);

strcpy(s[j+1],t);

8-12

{voidsort(char*[]);

char*p[10],str[10][20];

p[i]=str[i];

p[i]);

voidsort(char*s[])

char*temp;

if(strcmp(*(s+j),*(s+j+1))>

{temp=*(s+j);

*(s+j)=*(s+j+1);

*(s+j+1)=temp;

8-13

#include<

math.h>

{floatintegral(float(*)(float),float,float,int);

//对integarl函数的声明

floatfsin(float);

//对fsin函数的声明

floatfcos(float);

//对fcos函数的声明

floatfexp(float);

//对fexp函数的声明

floata1,b1,a2,b2,a3,b3,c,(*p)(float);

intn=20;

inputa1,b1:

%f,%f"

a1,&

b1);

inputa2,b2:

a2,&

b2);

inputa3,b3:

a3,&

b3);

p=fsin;

c=integral(p,a1,b1,n);

Theintegralofsin(x)is:

%f\n"

c);

p=fcos;

c=integral(p,a2,b2,n);

Theintegralofcos(x)is:

p=fexp;

c=integral(p,a3,b3,n);

Theintegralofexp(x)is:

floatintegral(float(*p)(float),floata,floatb,intn)

{inti

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

当前位置:首页 > IT计算机 > 电脑基础知识

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

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