哈尔滨工程大学c语言Word文档下载推荐.docx

上传人:b****6 文档编号:19320216 上传时间:2023-01-05 格式:DOCX 页数:50 大小:29.77KB
下载 相关 举报
哈尔滨工程大学c语言Word文档下载推荐.docx_第1页
第1页 / 共50页
哈尔滨工程大学c语言Word文档下载推荐.docx_第2页
第2页 / 共50页
哈尔滨工程大学c语言Word文档下载推荐.docx_第3页
第3页 / 共50页
哈尔滨工程大学c语言Word文档下载推荐.docx_第4页
第4页 / 共50页
哈尔滨工程大学c语言Word文档下载推荐.docx_第5页
第5页 / 共50页
点击查看更多>>
下载资源
资源描述

哈尔滨工程大学c语言Word文档下载推荐.docx

《哈尔滨工程大学c语言Word文档下载推荐.docx》由会员分享,可在线阅读,更多相关《哈尔滨工程大学c语言Word文档下载推荐.docx(50页珍藏版)》请在冰豆网上搜索。

哈尔滨工程大学c语言Word文档下载推荐.docx

#include<

stdio.h>

voidmain()

{charch[7]={"

12ab56"

inti,s=0;

for(i=0;

ch[i]>

='

0'

&

ch[i]<

9'

i+=2)

s=10*s+ch[i]-'

printf("

%d\n"

s);

}

答案:

1

2.

{inta[10]={1,2,2,3,4,3,4,5,1,5};

intn=0,i,j,c,k;

i<

10-n;

i++)

{c=a[i];

for(j=i+1;

j<

j++)

if(a[j]==c)

{n++;

for(k=j;

k<

k++)

a[k]=a[k+1];

}

(10-n);

a[i]);

}

12345

3.

#include<

{inti;

chara[]="

Time"

b[]="

Tom"

a[i]!

\0'

b[i]!

if(a[i]==b[i])

if(a[i]>

a'

a[i]<

z'

%c"

a[i]-32);

else

printf("

a[i]+32);

elseprintf("

*"

);

t*M

4.

#defineLEN4

{intj,c;

staticcharn[2][LEN+1]={"

8980"

"

9198"

for(j=LEN-1;

j>

=0;

j--)

{c=n[0][j]+n[1][j]-2*'

n[0][j]=c%10+'

for(j=0;

=1;

j++)puts(n[j]);

70789198

 

三、程序填空

程序的功能是在a数组中查找与x值相同的元素的所在位置。

{

inta[11],x,i;

Enter10integers:

\n"

for(i=1;

=10;

scanf("

Enterx:

"

x);

a[0]=x;

i=10;

while(x!

=a[i])

(1);

if(

(2))

%5d'

spositionis:

%4d\n"

x,(3));

else

%dNotbeenfound!

x);

(1)i—

(2)i>

=1

(3)i

数组a包括10个整型元素,从数组a的第2个元素开始,分别将后项减前项之差存入数组b,并按每行3个元素的格式输出数组b。

例如b[0]=a[1]-a[0]。

{inta[10],b[10],i;

i++)

a[i]);

for(i=1;

(2);

b[i]=a[i]-a[i-1];

10;

{printf("

%3d"

b[i]);

if((3))

(1)i<

=9

(2)i<

(3)i%3==0

四、程序改错

程序的功能是:

计算数组各元素之和,并存入首元素中。

inta[10]=[0];

/****found****/

inti;

i++)a[0]=a[0]+a[i];

a[0]);

(1)inta[3]={0};

(2)for(i=1;

3;

函数fun的功能是:

将数组s中的字符串的反序和正序连接后形成的新字符串放在数组t中。

例如,当数组s所存的字符串为"

ABCD"

时,

数组t应为"

DCBAABCD"

conio.h>

string.h>

voidfun(chars[],chart[])

inti,d;

d=strlen(s);

i<

d;

i++)/****found****/

t[i]=s[d-1-i];

i++)

t[d+i]=s[i];

t[2*d]='

/0'

chars[100],t[100];

clrscr();

\nPleaseenterstringS:

%s"

&

s);

fun(s,t);

\nTheresultis:

%s\n"

t);

(1)for(i=0;

(2)t[2*d]='

\0’

(3)scanf(“%s”,s)

五、程序问答

inta[100],i,j,n,p;

输入数值的个数n和数列a\n"

a[0]);

=n-1;

{

p=a[i];

j=i-1;

while(p<

a[j]&

=0)

{

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

j--;

a[j+1]=p;

n;

%d"

问题1:

该程序的功能是什么?

问题2:

如果先输入一个10,再输入下面的10个数:

1928374655

则该程序输出什么?

(1).升序

(2).1234556789

voidmain()

{inta[]={11,33,27,33,-1,22,-8,12};

inti,t,j;

for(i=0;

8-1;

for(j=8-1;

i;

if(a[j-1]<

a[j])

{t=a[j-1];

a[j-1]=a[j];

a[j]=t;

for(i=0;

8;

i++)printf(“%4d”,a[i]);

此程序的运行结果是什么?

若将函数中的语句:

a[j])

改成:

if(a[j-1]>

则程序的运行结果是什么?

(1).333327221211-1-8

(2).-8-1111222273333

六、编程

1.在一组数中找出最大与最小值之差。

inta[10],i,x,y;

pleaseinputthenumber:

x=a[0];

y=a[0];

{if(a[i]>

x)

x=a[i];

if(a[i]<

y)

y=a[i];

theansweris%d"

x-y);

2.用选择法将一组整数按降序排序。

inta[10],i,j,k,t;

pleaseinputthenumbers:

=8;

k=i;

=9;

if(a[j]>

a[k])

k=j;

t=a[k];

a[k]=a[i];

a[i]=t;

%d"

3.在一个按升序排列的数组中插入一个数,使数组仍有序。

inta[7]={3,5,7,9,11,23};

intb,i,k;

b);

a[6]=b;

i=5;

while(b<

a[i]&

i>

a[i+1]=a[i];

a[i]=b;

i--;

charuhoudeshuzu\n"

7;

4.用“顺序”查找法,在一组数中查找一个值为K的元素。

若有,输出YES;

若无,输出NO。

inta[10],i,j,k;

pleaseinputtheaimnumber:

k);

if(a[i]==k)

break;

if(i>

9)

NO\n"

else

YES\n"

5.输出以下形式的图案:

*******

*****

***

*

inti,j;

=4;

for(j=1;

=i-1;

"

=9-2*i;

6.将一个数组按逆序重新存放在该数组中。

inta[10],i,t;

10/2;

t=a[i];

a[i]=a[10-1-i];

a[10-1-i]=t;

7.打印一个5行的杨辉三角形。

inta[5][5]={0},i,j;

a[i][0]=a[i][i]=1;

for(i=2;

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

=i;

%3d"

a[i][j]);

8.用二维字符数组存储下列图形并输出。

*****

****

**

*

charc[5][5]={'

5;

for(j=i;

c[i][j]='

*'

c[i][j]);

9.计算二维数组主对角线元素之和。

inta[3][3],i,j,x;

a[i][j]);

x=0;

x=x+a[i][i];

theansweris%d\n"

10.用“折半”查找法,在一组按降序排列的数中查找一个值为K的元素。

inta[10]={10,9,8,7,6,5,4,3,2,1},l,r,m,k;

l=0;

r=9;

m=(1+r)/2;

while(l<

=r)

if(a[m]==k)

if(k>

a[m])

r=m-1;

l=m+1;

m=(l+r)/2;

if(l<

\nYES"

\nNO"

11.编写一个程序计算一个字符串的长度。

(不使用库函数)

chars[80];

intn=0;

gets(s);

while(s[n])n++;

length=%d"

n);

12.比较两个字符串S1、S2的大小。

(不使用库函数)若S1>

S2,输出1;

若S1=S2,输出0;

若S1<

S2输出-1。

chars1[80],s2[80];

inti,n;

gets(s1);

gets(s2);

i=0;

while(s1[i]&

s2[i]&

s1[i]==s2[i])i++;

if(!

s1[i]||s1[i]<

s2[i])

n=-1;

s2[i]||s1[i]>

n=1;

s1[i]&

!

n=0;

jieguoshi%d"

13.用“冒泡”法将一组数按升序排序。

inta[10],i,j,x;

9;

9-j;

a[i+1])

a[i]=a[i+1];

a[i+1]=x;

%4d"

14.在一个二维数组中形成并输出如下矩阵

11111

21111

32111

43211

54321

inta[5][5];

if(i<

=j)

a[i][j]=1;

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

%2d"

15.有一个3╳4的矩阵,求其中的最大元素的值及位置。

inta[3][4],i,j,x,l,r;

4;

x=a[0][0];

l=r=0;

if(a[i][j]>

x=a[i][j];

l=i;

r=j;

Maxnumberis%d,positionis%d,%d\n"

x,l,r);

1.根据下面的定义,能打印出字母M的语句是(D)。

structperson{charname[9];

intage;

};

structpersonclass[10]={"

John"

17,"

Paul"

19,"

Mary"

18,"

Adam"

16};

A.printf("

%c\n"

class[3].name);

B.printf("

class[3].name[1]);

C.printf("

class[2].name[1]);

D.printf("

class[2].name[0]);

2.若有以下结构体定义:

structexample

{intx1;

inty1;

则B是正确的使用方式。

A.structexample.x1=100;

B.structexamplexy;

xy.x1=100;

C.structxy;

D.structexamplexy={100};

3.下面结构体数组的定义,错误的是(D)。

A.structstudent

{intnum;

charname[10];

floatscore;

structstudentstu[30];

B.struct

}stu[30];

C.structstudent

D.structstu[30]

二、写出以下程序的运行结果

(1)

{structcmplx{intx;

inty;

}cnum[2]={1,3,2,7};

cnum[0].y/cnum[0].x*cnum[1].x);

6

(2)

{structdate

{intyear,month,dat;

}today;

sizeof(structdate));

(3)

{structMING

{struct{intx;

inty;

}in;

inta;

intb;

}e;

e.a=1;

e.b=2;

e.in.x=e.a*e.b;

e.in.y=e.a+e.b;

%d,%d"

e.in.x,e.in.y);

2,3

(4)

{

structabc

{inta,b,c;

structabcs[2]={{1,2,3},{4,5,6}};

intt;

t=s[0].a+s[1].b;

t);

}

(5)

structstudent

{ch

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

当前位置:首页 > 表格模板 > 合同协议

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

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