编程答案Word文档格式.docx

上传人:b****6 文档编号:16391718 上传时间:2022-11-23 格式:DOCX 页数:24 大小:18.98KB
下载 相关 举报
编程答案Word文档格式.docx_第1页
第1页 / 共24页
编程答案Word文档格式.docx_第2页
第2页 / 共24页
编程答案Word文档格式.docx_第3页
第3页 / 共24页
编程答案Word文档格式.docx_第4页
第4页 / 共24页
编程答案Word文档格式.docx_第5页
第5页 / 共24页
点击查看更多>>
下载资源
资源描述

编程答案Word文档格式.docx

《编程答案Word文档格式.docx》由会员分享,可在线阅读,更多相关《编程答案Word文档格式.docx(24页珍藏版)》请在冰豆网上搜索。

编程答案Word文档格式.docx

i<

=b;

i++)

if(i%2==0)

sum1+=i;

else

sum2+=i;

偶数和:

%d\n奇数和:

sum1,sum2);

6、

intfun(inta,inty)

intc,n1,n2,n3,n4;

n1=a%10;

n2=a/10;

n3=y%10;

n4=y/10;

c=n2*1000+n3*100+n1*10+n4;

returnc;

inta,b,c;

fun(a,b));

P72

1、

int*p,i;

intdata[10],data2[10];

for(i=0;

10;

{

scanf("

data[i]);

}

p=&

data[0];

for(i=9;

i>

=0;

i--)

data2[i]=*(p+i);

printf("

%d"

data2[i]);

printf("

\n"

);

return0;

2、

string.h>

chara[100];

inti;

gets(a);

for(i=0;

strlen(a);

if(a[i]>

='

a'

&

a[i]<

z'

a[i]=a[i]-32;

elseif(a[i]>

A'

Z'

a[i]=a[i]+32;

puts(a);

3、

charp[1000],*a;

inti,L;

a=&

p[0];

inputastring\n"

gets(p);

L=strlen(p);

for(i=1;

=L;

i++)

%c"

*(a+L-i));

inta[3][6],i,j,n,m,q,t,max,min;

n=m=q=t=0;

3;

for(j=0;

j<

6;

j++)

scanf("

a[i][j]);

max=a[0][0];

min=a[0][0];

if(max<

a[i][j])

max=a[i][j];

n=i;

m=j;

if(min>

min=a[i][j];

q=i;

t=j;

max=%data[%d,%d]\n"

max,n,m);

min=%data[%d,%d]\n"

min,q,t);

inti,min,max,temp,t1,t2,a[10],*p=a;

p+i);

min=max=a[0];

if(min<

a[i])

min=a[i];

t1=i;

if(max>

max=a[i];

t2=i;

temp=a[0];

a[0]=min;

a[t1]=temp;

temp=a[9];

a[9]=max;

a[t2]=temp;

a[i]);

#include"

stdio.h"

voidmain()

{

longx,s=0,j=0;

intn,i;

%ld"

x);

while(x)

n=x%10;

/*依次取N的各位数*/

if(n%2!

=0)

s=s*10+n;

/*将取出来的数进行累加,如输入的X=123456取出6,则S=0,取5,则S=5…………S=531*/

x=x/10;

/*去掉已取位数*/

/*下面的功能是将取出的结果531进行正序输出,你输入123456,输出结果为135*/

while(s)

i=s%10;

j=j*10+i;

s=s/10;

j);

P95

#include<

math.h>

doublefun(intx)

doubles=0.0;

for(i=2;

i<

=x;

i+=2)

s+=log(1.0*i);

s=sqrt(s);

returns;

}

%f\n"

fun(20));

voidfun(floata[],float*pmax,float*pmin,float*aver,intn)

*pmax=a[0];

*pmin=a[0];

*aver=0;

for(i=0;

=n-1;

if(*pmax<

*pmax=a[i];

if(*pmin>

*pmin=a[i];

*aver+=a[i];

*aver=*aver/n;

floata[100];

floatmax,min,aver;

intn;

请输入一个整数作为所需输入数的个数:

&

n);

请输入%d个数\n"

n);

%f"

a[i]);

fun(a,&

max,&

min,&

aver,n);

//参数max,min,aver均按地址传递

最大数为:

%f,最小数为:

%f,平均数为:

max,min,aver);

intff(chars[],charch)

inti=0,num=0;

while(s[i]!

\0'

if(s[i++]==ch)

num++;

returnnum;

charstr[]="

dazhutou"

;

printf("

ff(str,'

u'

));

voidc(longintm);

longintn;

请输入一个任意整数\n"

用递归法将其转换成字符串是:

if(n<

0)//考虑到输入可能为负数//

putchar('

-'

n*=-1;

//先将负数转换成整数,以免在自定义的函数内再讨论//

c(n);

voidc(longintm)

longintx;

x=m/10;

if(x!

=0)//递归的结束条件//

c(x);

putchar(m%10+'

0'

//字符0的ASCLL码是48,任意一个一位数加上48生成的//

}//ASCLL码对应的字符就是这个任意一位数本身了//

stdlib.h>

intfun(intx)

intr=0,d,c;

while

(1)

d=x%10;

r=r+d;

x=(x-d)/10;

if(x==0)

break;

returnr;

main()

intnum;

inputnum\n"

num);

fun(num));

intprime(int);

Inputthenumber:

if(prime(n))

\n%disaprime\n"

else

\n%disnotaprime.\n"

intprime(intNum)/*是素数返回1,否则返回0*/

{

inti,MaxDivisor=(int)sqrt(Num);

if(Num<

=2)

return0;

for(i=2;

=MaxDivisor;

{

if(Num%i==0)

return0;

/*Num能被i除,说明不是素数,返回0*/

}

return1;

7、

voidf(charx[],intm)

{charw[10];

inti,j,n;

n=strlen(x);

for(j=0;

m;

j++)

w[j]=x[n-m+j];

x[n-m]='

n-m;

w[m+i]=x[i];

%s\n"

w);

main()

{charg[10];

intm;

scanf("

%s"

g);

m);

f(g,m);

8、

#include"

string.h"

voidRever(char*s,inti)

if(i>

=0)

putchar(s[i]);

i--;

Rever(s,i);

chars[100];

gets(s);

Rever(s,strlen(s)-1);

9、

intfun(char*s,char*t)

intn=0;

while(*s&

*t)

if(*s++==*t++)

n++;

returnn;

chars[200],t[10];

s);

t);

出现次数%d\n"

fun(s,t));

P119

FILE*fp;

charc;

if((fp=fopen("

ccw.txt"

"

r+"

))==NULL)

cannotopen"

exit(0);

while(!

feof(fp))

c=fgetc(fp);

if(c=='

@'

c-=10;

fseek(fp,-1L,1);

fputc(c,fp);

fseek(fp,0L,1);

intfun(char*fname,inta,intb)

file.txt"

w"

))==NULL)

cannotopenfile\n"

fprintf(fp,"

%d%d%d%d%d"

a+b,a-b,a*b,a/b,a%b);

\nsucceed\n"

fclose(fp);

return1;

charfname[]="

inta,b;

%d%d"

fun(fname,a,b);

malloc.h>

#defineLENsizeof(structstudent)

structstudent

charnum[6];

charname[8];

charsex[2];

intage;

structstudent*next;

}stu[10];

structstudent*p,*pt,*head;

inti,length,iage,flag=1;

intfind=0;

while(flag==1)

请输入链表长度(小于10):

length);

if(length<

10)

flag=0;

length;

p=(structstudent*)malloc(LEN);

if(i==0)

head=pt=p;

pt->

next=p;

pt=p;

No.:

p->

name:

name);

sex:

sex);

age:

p->

age);

p->

next=NULL;

p=head;

\nNo.namesexage\n"

while(p!

=NULL)

%4s%8s%6s%6d\n"

num,p->

name,p->

sex,p->

p=p->

next;

inputage:

iage);

pt=head;

p=pt;

if(pt->

age==iage)

p=pt->

head=pt=p;

find=1;

else

pt=pt->

while(pt!

if(pt->

p->

next=pt->

find=1;

p=pt;

if(!

find)

notfound%d."

iage);

%4s%8s"

%6s%6d\n"

#defineN10

typedefstructstudent

floatscore;

}STU;

STU*create()

STU*p,*head=NULL,*tail=head;

N;

p=(STU*)malloc(sizeof(STU));

%d%f"

num,&

score);

if(p->

num<

0)

free(p);

if(head==NULL)

head=p;

tail->

tail=p;

returnhead;

voidoutput(STU*p)

while(p!

%d\t%.2f\n"

p=p->

STU*link(STU*p1,STU*p2)

STU*p,*head;

if(p1->

score>

p2->

score)

head=p=p1;

p1=p1->

head=p=p2;

p2=p2->

while(p1!

=NULL&

p2!

next=p1;

p=p1;

next=p2;

p=p2;

if(p1!

intmain(intargc,char*argv[])

STU*a,*b,*c;

\n请输入链表a的信息,学号小于零时结束输入:

格式(学号成绩)\n"

a=create();

\n请输入链表b的信息,学号小于零时结束输入:

b=create();

\n链表a的信息为:

output(a);

\n链表b的信息为:

output(b);

c=link(a,b);

\n合并后的链表信息为:

output(c);

#defineMAXSIZE100

typedefintdatatype;

typedefstructlink_node{

datatypedata;

structlink_node*next;

}node;

voidinit(node**p)

intx;

node*pre,*q;

pre=*p;

while(x!

q=(node*)malloc(sizeof(node));

q->

data=x;

pre)

*p=pre=q;

else{

pre->

next=q;

pre=q;

pre->

node*nizhuan(node*p)

node*r;

r=p;

pre=p;

p||!

next)returnp;

else

q=pre->

while(q->

next)

pre=q;

q=q->

pre->

p=pre;

p=q;

r->

returnp;

voiddisplay(node*p)

node*q;

q=p;

q)printf("

单链表为空!

else{

while(q)

%5d"

q->

data);

node*p=NULL;

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

当前位置:首页 > 初中教育 > 初中作文

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1