改错题Word文档下载推荐.docx

上传人:b****6 文档编号:19024598 上传时间:2023-01-03 格式:DOCX 页数:44 大小:29.74KB
下载 相关 举报
改错题Word文档下载推荐.docx_第1页
第1页 / 共44页
改错题Word文档下载推荐.docx_第2页
第2页 / 共44页
改错题Word文档下载推荐.docx_第3页
第3页 / 共44页
改错题Word文档下载推荐.docx_第4页
第4页 / 共44页
改错题Word文档下载推荐.docx_第5页
第5页 / 共44页
点击查看更多>>
下载资源
资源描述

改错题Word文档下载推荐.docx

《改错题Word文档下载推荐.docx》由会员分享,可在线阅读,更多相关《改错题Word文档下载推荐.docx(44页珍藏版)》请在冰豆网上搜索。

改错题Word文档下载推荐.docx

例如,调用fun函数之前给字符串输入:

ABCDeFGH,

调用后字符串中的内容为:

eABCDFGH。

fun(char*p)

max,*q;

i=0;

max=p[i];

while(p[i]!

=0)

if(max<

p[i])

q=p+i

i++;

wihle( 

q>

p)

*q=*(q-1);

q--;

p[0]=max;

str[80];

Enterastring:

gets(str);

\nTheoriginalstring:

puts(str);

fun(str);

\nThestringaftermoving:

printf("

\n\n"

3、给定程序MODI1.C中函数fun的功能是:

根据整型形参m,计算如下公式的值。

1

y=------- 

--------- 

---------+……+ 

-------

100*100 

200*200 

300*300 

m*m

例如,若m=2000,则应输出:

0.000160。

/************found************/

fun(int 

m)

doubley=0,d;

i;

for(i=100,i<

=m,i+=100)

d=(double)i*(double)i;

y+=1.0/d;

return(y);

main()

n=2000;

printf("

\nTheresultis%lf\n"

fun(n));

4、给定程序MODI1.C中函数fun的功能是:

读入一个字符串(长度<20),将该字符串中的所有字符按ASCII码升序排序后输出。

例如,若输入:

edcba,则应输出:

abcde。

voidfun(chart[])

{

charc;

i,j;

/**********found***********/

for(i=strlen(t);

i;

i--)

for(j=0;

j<

j++)

if(t[j]<

t[j+1])

c=t[j];

t[j]=t[j+1];

t[j+1]=c;

chars[81];

\nPleaseenteracharacterstring:

"

);

gets(s);

\n\nBeforesorting:

\n 

\"

s);

fun(s);

\nAftersortingdecendingly:

5、给定程序MODI1.C中fun函数的功能是:

分别统计字符串中大写字母和小写字母的个数。

例如,给字符串s输入:

AAaaBBb123CCccccd,则应输出结果:

upper=6,lower=8。

voidfun(char*s,inta,intb)

while(*s)

if(*s>

='

A'

&

&

*s<

Z'

*a=a+1;

a'

z'

*b=b+1;

s++;

s[100];

upper=0,lower=0;

\nPleaseastring:

gets(s);

fun(s, 

upper,&

lower);

\nupper=%d 

lower=%d\n"

upper,lower);

6、给定程序MODI1.C中函数fun的功能是:

统计substr所指子字符串在str所指字符串中出现的次数。

例如,若字符串为aaaslkaaas,子字符串为as,则应输出2。

fun(char*str,char*substr)

inti,j,k,num=0;

for(i=0,str[i],i++)

for(j=i,k=0;

substr[k]==str[j];

k++,j++)

If(substr[k+1]=='

\0'

num++;

break;

returnnum;

charstr[80],substr[80];

Inputastring:

);

gets(str);

Inputasubstring:

gets(substr);

%d\n"

fun(str,substr));

7、给定程序MODI1.C中函数fun的功能是:

根据整型形参m的值,计算如下公式的值。

t=1-------------……------

2*2 

3*3 

例如,若m中的值为:

5,则应输出:

0.536389。

doublefun(intm)

double 

y=1.0;

/**************found**************/

for(i=2;

i<

m;

i++)

y-=1/(i*i);

intn=5;

8、给定程序MODI1.C中函数fun的功能是:

逐个比较p、q所指两个字符串对应位置中的字符,把ASCII值大或相等的字符依次存放到c所指数组中,形成一个新的字符串。

例如,若主函数中a字符串为:

aBCDeFgH,

主函数中b字符串为:

ABcd,

则c中的字符串应为:

aBcdeFgH。

string.h>

void 

fun(char*p,char*q,char*c)

intk=1;

while(*p!

=*q)

if(*p<

*q) 

c[k]=*q;

c[k]=*p;

if(*p)p++;

if(*q)q++;

k++;

a[10]="

aBCDeFgH"

b[10]="

ABcd"

c[80]={'

};

fun(a,b,c);

Thestringa:

puts(a);

Thestringb:

puts(b);

Theresult 

:

puts(c);

9、给定程序MODI1.C中函数fun的功能是:

从s所指字符串中删除所有小写字母c。

fun(char 

*s)

i,j;

for(i=j=0;

s[i]!

='

;

if(s[i]!

c'

s[j]=s[i];

s[i]='

s[80];

gets(s);

Theoriginalstring:

puts(s);

fun(s);

Thestringafterdeleted:

10、给定程序MODI1.C中函数fun的功能是:

根据以下公式求π值,并作为函数值返回。

例如,给指定精度的变量eps输入0.0005时,应当输出Pi=3.140578。

π 

23 

4

─=1+─+─×

─+─×

─×

─+……

57 

9

math.h>

doublefun(double 

eps)

s,t;

n=1;

s=0.0;

t=0;

while(t>

s+=t;

t=t*n/(2*n+1);

n++;

return(s);

x;

\nPleaseenteraprecision:

scanf("

%lf"

&

x);

\neps=%lf,Pi=%lf\n\n"

x,fun(x));

11、给定程序MODI1.C中函数fun的功能是:

找出一个大于形参m且紧随m的素数,并作为函数值返回。

intfun(intm)

inti,k;

for(i=m+1;

;

i++){

for(k=2;

k<

k++)

if(i%k!

=0)

break;

if(k<

i)

return(i);

voidmain()

intn;

n=fun(20);

n=%d\n"

n);

12、给定程序MODI1.C中函数fun的功能是:

首先把b所指字符串中的字符按逆序存放,然后将a所指字符串中的字符和b所指字符串中的字符,按排列的顺序交叉合并到c所指数组中,过长的剩余字符接在c所指数组的尾部。

例如,当a所指字符串中的内容为"

abcdefg"

,b所指字符串中的内容为"

1234"

时,c所指数组中的内容应该为"

a4b3c2d1efg"

而当a所指字符串中的内容为"

,b所指字符串中的内容

为"

1g2f3e4dcba"

voidfun(char 

*a,char 

*b,char 

*c)

i,j;

ch;

i=0;

j=strlen(b)-1;

while(i>

j)

ch=b[i];

b[i]=b[j];

b[j]=ch;

j--;

while(*a||*b){

If(*a)

{*c=*a;

c++;

a++;

}

if(*b)

{*c=*b;

b++;

*c=0;

s1[100],s2[100],t[200];

\nEnters1string:

scanf("

%s"

s1);

\nEnters2string:

s2);

fun(s1,s2,t);

\nTheresultis:

%s\n"

t);

13、给定程序MODI1.C中函数fun的功能是:

从低位开始取出长整型变量s中偶数位上的数,依次构成一个新数放在t中。

高位仍在高位,低位仍在低位。

例如,当s中的数为:

7654321时,t中的数为:

642。

voidfun(long 

s,longt)

long 

sl=10;

s/=10;

*t=s%10;

while(s<

0)

s=s/100;

*t=s%10*sl+*t;

sl=sl*10;

s,t;

\nPleaseenters:

%ld"

&

s);

fun(s,&

t);

Theresultis:

%ld\n"

t);

14、给定程序MODI1.C中函数fun的功能是:

计算小于形参k的最大的10个能被13或17整除的自然数之和。

k的值由主函数传入,若k的值为500,则函数值为4622。

intfun(int 

k)

intm=0, 

mc=0,j;

while((k>

=2)&

(mc<

10))

if((k%13=0)||(k%17=0))

{m=m+k;

mc++;

k--;

returnm;

_____

main()

fun(500));

15、给定程序MODI1.C是建立一个带头结点的单向链表,并用随机函数为各结点数据域赋值。

函数fun的作用是求出单向链表结点(不包括头结点)数据域中的最大值,并且作为函数值返回。

stdlib.h>

typedef 

struct 

aa

data;

aa 

*next;

}NODE;

fun( 

NODE 

*h)

{int 

max=-1;

*p;

/***********found**********/

p=h;

while(p)

if(p->

data>

max)

max=p->

p=h->

next;

max;

outresult(int 

s,FILE*pf)

fprintf(pf,"

\nThemaxinlink 

s);

*creatlink(int 

n,int 

m)

*h,*p,*s,*q;

i,x;

h=p=(NODE*)malloc(sizeof(NODE));

h->

data=9999;

for(i=1;

i<

=n;

s=(NODE*)malloc(sizeof(NODE));

s->

data=rand()%m;

next=p->

next;

p->

next=s;

p=p->

next=NULL;

h;

outlink(NODE 

*h,FILE 

*pf)

\nTHE 

LIST:

\n\n 

HEAD"

->

%d"

p->

data);

p=p->

*head;

m;

head=creatlink(12,100);

outlink(head,stdout);

m=fun(head);

RESULT 

outresult(m,stdout);

16、给定程序MODI1.C中函数fun的功能是:

从N个字符串中找出最长的那个串,并将其地址作为函数值返回。

各字符串在主函数中输入,并放入一个字符串数组中。

#define 

5

81

fun(char 

(*sq)[M])

*sp;

sp=sq[0];

for(i=0;

i<

N;

i++)

if(strlen(sp)<

strlen(sq[i]))

sp=sq[i];

sq;

str[N][M],*longest;

Enter%dlines:

N);

i++)gets(str[i]);

\nTheNstring 

i++)puts(str[i]);

longest=fun(str);

\nThelongeststring:

puts(longest);

17、给定程序MODI1.C的功能是:

读入一个英文文本行,将其中每个单词的第一个字母改成大写,然后输出此文本行(这里的“单词”是指由空格隔开的字符串)。

例如,若输入:

Iamastudenttotaketheexamination.,

则应输出:

IAmAStudentToTakeTheExamination.。

ctype.h>

/***

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

当前位置:首页 > 工程科技 > 电力水利

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

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