中国海洋大学C程上机答案Word文档下载推荐.docx

上传人:b****3 文档编号:17063200 上传时间:2022-11-28 格式:DOCX 页数:23 大小:17.50KB
下载 相关 举报
中国海洋大学C程上机答案Word文档下载推荐.docx_第1页
第1页 / 共23页
中国海洋大学C程上机答案Word文档下载推荐.docx_第2页
第2页 / 共23页
中国海洋大学C程上机答案Word文档下载推荐.docx_第3页
第3页 / 共23页
中国海洋大学C程上机答案Word文档下载推荐.docx_第4页
第4页 / 共23页
中国海洋大学C程上机答案Word文档下载推荐.docx_第5页
第5页 / 共23页
点击查看更多>>
下载资源
资源描述

中国海洋大学C程上机答案Word文档下载推荐.docx

《中国海洋大学C程上机答案Word文档下载推荐.docx》由会员分享,可在线阅读,更多相关《中国海洋大学C程上机答案Word文档下载推荐.docx(23页珍藏版)》请在冰豆网上搜索。

中国海洋大学C程上机答案Word文档下载推荐.docx

2.

voidfun(intk,int*p)

inti,j=0;

for(i=2;

i<

=k;

i++)

while(k!

=i)

if(k%i==0)

{

p[j]=i;

j=j+1;

k=k/i;

}

elsebreak;

p[j]=k;

p[j+1]=-1;

intx,a[17]={0},i;

printf("

Enteranumber(2-32767):

scanf("

%d"

x);

while(x<

2);

fun(x,a);

for(i=0;

a[i]!

=-1;

if(a[i]!

=a[i+1])

printf("

%d"

a[i]);

"

3.

#defineN6

voidfun(int*x,intn)

inti,k,j,p=0,m=0;

2;

k=i;

for(j=i+1;

j<

n;

j++)

if(x[j]>

x[k])

k=j;

m=x[i];

x[i]=x[k];

x[k]=m;

inta[N],i;

N;

a[i]);

fun(a,N);

\n"

4.

intfun(int*x,intn)

inti,j,m,p,d=0;

m=x[0];

7;

x[i]=x[i]+x[i+1];

x[7]=x[7]+m;

for(j=0;

n-i;

x[j+1])

p=x[j];

x[j]=x[j+1];

x[j+1]=p;

if(x[i]%2!

=0)

d++;

returnd;

inta[8],i,n;

8;

n=fun(a,8);

for(i=0;

n=%d\n"

n);

5.

intfun(intx,longinty)

inti,n=0,m=0;

while(y-m>

n++;

m=m+pow(x,n);

returnn-1;

intx;

longy;

%d%ld"

x,&

y);

fun(x,y));

6.

string.h>

#defineN30

intfun(char(*ss)[N],intm,char*s)

inti,j,k;

s=ss[0];

m;

if(strlen(s)<

strlen(ss[i]))

s=ss[i];

j=strlen(s);

str=%s"

s);

returnj;

chara[8][N],b[N];

inti,len;

gets(a[i]);

len=fun(a,8,b);

len=%d"

len);

7.

intcountw(char*str)

charc;

inti=0,num=0,word=0;

while((c=str[i])!

='

\0'

if(c=='

'

word=0;

elseif(word==0)

word=1;

num++;

i++;

returnnum;

chars[200];

gets(s);

Thereare%dwords.\n"

countw(s));

8.

voidfun(char*str)

charc,b;

inti=0,j,m,n;

while(c=='

0'

if(str[i+1]=='

j=i;

while((b=str[j])!

{

str[j]=str[j+1];

j++;

}

i++;

puts(str);

chars[100];

puts("

Enterastring:

fun(s);

puts(s);

9.

voidfun(intx,intk,int*p)

inti,m=0,n;

x=x+1;

n=sqrt(x);

while(m<

k)

for(i=2;

=n;

if(x%i==0)

break;

if(i>

=n)

p[m]=x;

m++;

}

x++;

n=sqrt(x);

inta,b,n[1000]={0},i;

%d%d"

a,&

b);

fun(a,b,n);

b;

n[i]);

10.

#include<

intisPrime(intnum)

inti;

=sqrt(num);

if((num%i)==0)

return0;

return1;

intconvert(intnum)

intk=0;

do

k=k*10+(num%10);

while((num/=10)!

=0);

returnk;

intfun(inta,intb)

inti,res=0;

for(i=a;

=b;

if(isPrime(i)&

&

isPrime(convert(i)))

printf("

i);

res++;

returnres;

 

voidmain()

intnum,a,b;

num=fun(a,b);

num=%d\n"

num);

11.

voidfun(char*a,char*b)

inti,j;

for(i=0,j=0;

a[i];

b[j++]=a[i++];

if(!

(i%3))

b[j++]='

#'

;

b[j]='

charx[80],y[120];

gets(x);

fun(x,y);

puts(y);

12.

intfun(intk)

inti,j,m,p=0;

for(i=1;

=5;

for(j=1;

=3;

if(i+j==k)

p++;

for(m=1;

m<

=6;

m++)

if(i+j+m==k)

p++;

returnp;

intx,n;

n=fun(x);

13.

charm;

inti,j,p,q,x;

x=strlen(str);

x;

i=i+2)

x-i;

j=j+2)

if(str[j]>

str[j+2])

m=str[j];

str[j]=str[j+2];

str[j+2]=m;

}

}

chars[100]={0};

14.

voidfun(int*a,intn,inty)

inti,j;

10;

if(y>

=a[i])

for(j=9;

j>

=i;

j--)

a[j+1]=a[j];

a[i]=y;

break;

a[10]=y;

inti,a[11]={20,18,16,14,12,10,8,6,4,2},x;

voidfun(int*,intn,inty);

fun(a,10,x);

11;

*(a+i));

15.

intfun(char*str,charch)

inti,j,m=0,p=0;

p=strlen(str);

m=strlen(str);

while(str[i]==ch)

for(j=i;

str[j]=str[j+1];

str[j+1]='

m=strlen(str);

if(m==p)

m=-1;

returnm;

{

chara[80]={0},b;

intn;

Pleaseinputastring:

gets(a);

Pleaseinputadeletecharacter:

b=getchar();

n=fun(a,b);

if(n==-1)

Nofind%c\n"

elseprintf("

%s,n=%d\n"

a,n);

16.

intfun(char*str)

inti,j,m=1,p,x,q;

p;

i;

x=str[i];

q=str[j];

if(x==q)

if(j+1>

chars[80];

gets(s);

n=fun(s);

17.

intfun(intm,intn,int*p)

inti=0,num=0;

intf1=1,f2=1;

while(f1<

if((f1>

=m&

f1<

=n))

p[i++]=f1;

num++;

if((f2>

f2<

=n)&

f2!

=p[i-1])

p[i++]=f2;

f1=f1+f2;

f2=f2+f1;

returnnum;

inta,b,n,c[22]={0},i;

n=fun(a,b,c);

%6d"

c[i]);

\nn=%d\n"

18.

char*fun(char*s1,char*s2,intn)

inti,m=0,p=0,x=0;

m=strlen(s1);

if(m<

n)

for(p=m-1,x=n-1;

p>

=0,x>

=n-m;

p--,x--)

s2[x]=s1[p];

n-m;

s2[i]='

*'

if(m>

=m-n,x>

if(m==n)

strcpy(s2,s1);

charc1[80]={0},c2[80]={0};

intn;

gets(c1);

请输入n"

n);

fun(c1,c2,n);

puts(c2);

19.

char*fun(char*str)

inti,m;

if((str[i]>

A'

str[i]<

X'

)||(str[i]>

a'

x'

))

str[i]=char(int(str[i])+2);

continue;

if(str[i]>

Y'

Z'

str[i]=char(int(str[i])-24);

y'

z'

chars[80]={0};

20.

voidfun(char*s)

charp;

inti,j,m;

m=strlen(s);

if(m%2==0)

p=s[m-1];

for(i=m-1;

1;

i=i-2)

s[i]=s[i-2];

s[1]=p;

if(m%2!

p=s[m-2];

for(i=m-2;

chara[80];

gets(a);

fun(a);

puts(a);

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

当前位置:首页 > 工程科技 > 机械仪表

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

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