1、#includevoid main() char ch7=12ab56 int i,s=0; for(i=0;chi=0&chi9i+=2) s=10*s+chi- printf(%dn,s); 答案:12. int a10=1,2,2,3,4,3,4,5,1,5; int n=0,i,j,c,k;i10-n;i+) c=ai; for(j=i+1;jj+) if(aj=c) n+;for(k=j;kk+) ak=ak+1; (10-n);,ai);123453. #include aai=0;j-) c=n0j+n1j-2* n0j=c%10+ for(j=0;=1;j+) puts(nj)
2、;7078 9198三、程序填空程序的功能是在a数组中查找与x值相同的元素的所在位置。int a11,x,i;Enter 10 integers :nfor(i=1;=10;scanf(Enter x :x);a0=x;i=10;while(x!=ai) (1) ;if( (2) )%5ds position is : %4dn,x, (3) );else%d Not been found!,x);(1) i(2) i=1(3) i数组a包括10个整型元素,从数组a的第2个元素开始,分别将后项减前项之差存入数组b,并按每行3个元素的格式输出数组b。例如b0=a1-a0。 int a10,b10
3、,i;i+) ai); for(i=1; (2) ; bi=ai-ai-1;10; printf(%3d,bi); if( (3) ) (1) i=9(2) istring.hvoid fun (char s, char t) int i, d; d = strlen(s); id; i+) /* found */ ti=sd-1-i; i+) td+i=si; t2*d = /0 char s100, t100; clrscr();nPlease enter string S:%s, &s); fun(s, t);nThe result is: %sn, t);(1) for(i=0;(2)
4、 t2*d=0 (3) scanf(“%s”,s)五、程序问答int a100, i, j, n, p;输入数值的个数n 和数列ana0);=n-1; p=ai; j=i-1; while(paj&=0) aj+1=aj; j-; aj+1=p;n;%d 问题1:该程序的功能是什么?问题2:如果先输入一个10,再输入下面的10个数: 1 9 2 8 3 7 4 6 5 5 则该程序输出什么?(1). 升序 (2). 1 2 3 4 5 5 6 7 8 9void main( )int a=11,33,27,33,-1,22,-8,12;int i,t,j;for (i=0;8-1;for (j
5、=8-1;i;if (aj-1则程序的运行结果是什么?(1). 33 33 27 22 12 11 -1 -8(2). -8 -1 11 12 22 27 33 33六、编程1. 在一组数中找出最大与最小值之差。 int a10,i,x,y;please input the number: x=a0; y=a0; if(aix) x=ai; if(aiak) k=j; t=ak; ak=ai; ai=t; %d3. 在一个按升序排列的数组中插入一个数,使数组仍有序。 int a7=3,5,7,9,11,23; int b,i,k;b); a6=b; i=5; while(b ai+1=ai;
6、ai=b; i-;cha ru hou de shu zu n7;4. 用“顺序”查找法,在一组数中查找一个值为K的元素。若有,输出YES;若无,输出NO。 int a10,i,j,k;please input the aim number:k); if(ai=k) break; if(i9)NOn elseYESn5. 输出以下形式的图案: * * * * int i,j;=4; for(j=1;=i-1; =9-2*i;6. 将一个数组按逆序重新存放在该数组中。 int a10,i,t;10/2; t=ai; ai=a10-1-i; a10-1-i=t;7. 打印一个5行的杨辉三角形。 i
7、nt a55=0,i,j; ai0=aii=1; for(i=2; aij=ai-1j+ai-1j-1;=i; %3d,aij);8. 用二维字符数组存储下列图形并输出。* * * char c55=5; for(j=i; cij=*,cij);9. 计算二维数组主对角线元素之和。 int a33,i,j,x;aij); x=0; x=x+aii;the answer is %dn10. 用“折半”查找法,在一组按降序排列的数中查找一个值为K的元素。 int a10=10,9,8,7,6,5,4,3,2,1,l,r,m,k; l=0; r=9; m=(1+r)/2; while(lam) r=
8、m-1; l=m+1; m=(l+r)/2; if(lS2 ,输出1;若S1=S2,输出0;若S1S2输出-1。 char s180,s280; int i,n; gets(s1); gets(s2); i=0; while(s1i&s2i&s1i=s2i)i+; if(!s1i|s1i n=1;s1i&! n=0;jie guo shi %d13. 用“冒泡”法将一组数按升序排序。 int a10,i,j,x;9;9-j;ai+1) ai=ai+1; ai+1=x;%4d14. 在一个二维数组中形成并输出如下矩阵 1 1 1 1 1 2 1 1 1 1 3 2 1 1 1 4 3 2 1 1
9、 5 4 3 2 1 int a55; if(i x=aij; l=i; r=j;Max number is %d,position is %d,%dn,x,l,r);1. 根据下面的定义,能打印出字母M的语句是( D )。struct personchar name9;int age; ;struct person class10=John,17,Paul,19,Mary,18,Adam,16;A.printf(%cn,class3.name);B.printf(,class3.name1);C.printf(,class2.name1);D.printf(,class2.name0);2.
10、 若有以下结构体定义:struct exampleint x1;int y1;则 B 是正确的使用方式。Astruct example.x1=100; Bstruct example xy;xy.x1=100;Cstruct xy; Dstruct example xy=100;3. 下面结构体数组的定义,错误的是( D )。Astruct student int num; char name10; float score;struct student stu30;B structstu30;C struct student D struct stu30 二、写出以下程序的运行结果(1) st
11、ruct cmplx int x; int y; cnum2=1,3,2,7;,cnum0.y/cnum0.x*cnum1.x);6(2) struct date int year,month,dat; today;,sizeof(struct date);(3) struct MING struct int x; int y; in; int a;int b;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) struct abc int a,b,c;struct abc s2=1,2,3,4,5,6;int t; t=s0.a+s1.b;,t); (5)struct studentch
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1