注意:源程序存放在考生文件夹的BLANK1.C中。
不得增行或删行,也不得更改程序的结构!
给定源程序:
#include
typedef struct
{int num;
char name[10];
}PERSON;
/**********found**********/
void fun(PERSON ___1___)
{
/**********found**********/
___2___ temp;
if(std[0].num>std[1].num)
{temp=std[0]; std[0]=std[1]; std[1]=temp;}
if(std[0].num>std[2].num)
{temp=std[0]; std[0]=std[2]; std[2]=temp;}
if(std[1].num>std[2].num)
{temp=std[1]; std[1]=std[2]; std[2]=temp;}
}
main()
{PERSON std[]={ 5,"Zhanghu",2,"WangLi",6,"LinMin" };
int i;
/**********found**********/
fun(___3___);
printf("\nThe result is :\n");
for(i=0; i<3; i++)
printf("%d,%s\n",std[i].num,std[i].name);
}
解题答案:
/**********第一空**********/
void fun(PERSON *std)
/**********第二空**********/
PERSON temp;
/**********第三空**********/
fun(std);
****************************************** [NextPage] 二、改错题:给定程序MODI1.C中函数fun的功能是:将 m(1≤m≤10)个字符串连接起来,组成一个新串,放入pt所指存储区中。例如:把3个串:"abc","CD","EF"连接起来,结果是 "abcCDEF"。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动 main 函数,不得增行或删行,也不得更改程序的结构!
给定源程序:
#include
#include
void fun (char str[][10], int m, char *pt)
{
/************found************/
Int k, q, i ;
for (k = 0; k < m; k++)
{q = strlen (str [k]);
for (i=0; i
/************found************/
pt[i] = str[k,i] ;
pt += q ;
pt[0] = 0 ;
}
}
main()
{int m, h ;
char s[10][10], p[120] ;
printf("\nPlease enter m:");
scanf("%d", &m); gets(s[0]);
printf("\nPlease enter %d string:\n", m);
for (h = 0; h < m; h++) gets(s[h]);
fun(s, m, p);
printf("\nThe result is : %s\n", p);
}
解题答案:
/************found************/
int k, q, i;
/************found************/
pt[i]=str[k][i];
******************************************
[NextPage] 三.、程序题:程序定义了N×N的二维数组,并在主函数中自动赋值。请编写函数 fun( int a[][N]),函数的功能是:使数组左下三角元素中的值全部置成0 。
例如:a 数组中的值为
| 1 9 7 | | 0 9 7 | a = | 2 3 8 | 则返回主程序后a数组中的值应为 | 0 0 8 | | 4 5 6 | | 0 0 0 |
注意: 部分源程序存在文件PROG1.C中。
请勿改动主函数main和其它函数中的任何内容,仅在函数fun的花括号中填入
你编写的若干语句。
给定源程序:
#include
#include
#define N 5
void fun (int a[][N])
{
}
NONO()
{/* 本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。 */
FILE *rf, *wf ;
int i, j, a[5][5] ;
rf = fopen("in.dat","r");
wf = fopen("out.dat","w");
for(i = 0 ; i < 5 ; i++)
for(j = 0 ; j < 5 ; j++)
fscanf(rf, "%d ", &a[i][j]);
fun(a);
for (i = 0; i < 5; i++) {
for (j = 0; j < 5; j++) fprintf(wf, "M", a[i][j]);
fprintf(wf, "\n");
}
fclose(rf);
fclose(wf);
}
main ()
{int a[N][N], i, j;
printf("***** The array *****\n");
for (i =0; i
{for (j =0; j
{a[i][j] = rand(); printf("M", a[i][j]);}
printf("\n");
}
fun (a);
printf ("THE RESULT\n");
for (i =0; i
{for (j =0; j
printf("\n");
}
NONO();
参考答案:
int fun ( int a[][N] )
{
int i, j;
for(i = 0 ; i < N ; i++)
for(j = 0 ; j <= i; j++)
a[i][j] = 0 ;
}
| 广告合作:400-664-0084 全国热线:400-664-0084 Copyright 2010 - 2017 www.my8848.com 珠峰网 粤ICP备15066211号 珠峰网 版权所有 All Rights Reserved
|