阅读以下函数说明和C语言函数,将应填入(n)处的字句写在对应栏内。
[函数2.1说明]
将一个正整数分解质因数。例如:输入90,打印出90=2×3×3×5。
[函数2.1]
fun 1 ( int n )
{
int i;
for ( i=2;i<=n; i++)
{
while (((1))
{
if (n %i==0 )
{ printf ( "%d*",i );
(2)
}
else
break;
}
}
printf ( "%d",n ) ;}
[函数2.2说明]
下面程序的功能是:海滩上有一堆桃子,5只猴子来分。第1只猴子把这堆桃子平均分为5份,多了一个,这只猴子把多的一个扔入海中,拿走了一份。第2只猴子把剩下的桃子又平均分成5份,又多了一个,它同样把多的一个扔入海中,拿走了一份,第3、第4、第5只猴子都是这样做的,问海滩上原来最少有多少个桃子?
[函数2.2]
main ( )
{int i, m, j, k, count;
for ( i=4;i<10000;i+=4 )
{ count=0;
(3);
for ( k=0;k<5;k++ )
{
(4);
i=j;
if ( j%4==0 )
(5);
else
break;
}
i=m;
if ( count==4 )
{printf ( "%d\n", count) ;
break;}
}
}
第1题:
阅读以下函数说明和C语言函数,将应填入(n)处的字句写在答题纸的对应栏内。
【函数2.1说明】
递归函数sum(int a[], int n)的返回值是数组a[]的前n个元素之和。
【函数2.1】
int sum (int a[],int n)
{
if(n>0) return (1);
else (2);
}
【函数2.2说明】
有3个整数,设计函数compare(int a,int b,int c)求其中最大的数。
【函数2.2】
int compare (int a, int b, int c )
{ int temp, max;
(3) a:b;
(4) temp:c;
}
【函数2.3说明】
递归函数dec(int a[],int n)判断数组a[]的前n个元素是否是不递增的。不递增返回 1,否则返回0。
【函数2.3】
int dec( int a[], int n )
{
if(n<=1) return 1;
if(a[0]<a[1]) return 0;
return (5);
}
第2题:
阅读以下函数说明和C语言函数,将应填入(n)处的字句写在对应栏内。
[说明]
已知r[1...n]是n个记录的递增有序表,用折半查找法查找关键字为k的记录。若查找失败,则输出“failure",函数返回值为0;否则输出“success”,函数返回值为该记录的序号值。
[C函数]
int binary search(struct recordtype r[],int n,keytype k)
{ intmid,low=1,hig=n;
while(low<=hig){
mid=(1);
if(k<r[mid].key) (2);
else if(k==r[mid].key){
printf("succesS\n");
(3);
}
else (4);
}
printf("failure\n");
(5);
}
第3题:
阅读以下函数说明和C语言函数,将应填入(n)处的字句写在对应栏内。
[说明1]
函数int function(int a)的功能是判断指定的正整数是否为素数,若是,返回1,否则返回0。
[C函数1]
int function(int a)
{ int yes,i;
i=2;yes=1;
while(i<=a/2 && (1) ){
if( (2) ) yes=0;
i++;
}
return yes;
}
[说明2]
函数int deleteARR(int*arr,intn)的功能是指定的有序数组压缩成各元素互不相同的有序数组,即相同数只保留一个,多余的被删除。函数返回值是互不相同的元素个数。
[C函数2]
int deleteARR(int*arr,int n)
{ int k,j;
k=0;j=1;
while(j<n){
if( (3) )
(4)=arr[j];
j++;
}
return (5);
}
第4题:
阅读下列程序说明和C程序,将应填入(n)处的字句写在对应栏内。
[函数2.1说明]
下面程序的功能是计算x和y的最小公倍数。
[函数2.1]
main()
{ int m,n,d,r;
seanf("%d %d",&m,&n);
if(m<n) {r=m;m=n;n=r;}
(1);
while (d%n! =0) (2);
printf("%d\n",d);
}
[函数2.2说明]
下述程序接收键盘输入,直到句点“.”时结束。输入的字符被原样输出,但连续的空格输入将转换成一个空格。
[函数2.2]
include <stdio.h>
main()
{ char c,preChar='\0';
c = getchar();
while(c! = '.'){
if((3)) putchar(c);
else if(preChar! =' ') putchar(c);
(4);
c=(5);
}
}
第5题:
试题三(共 15 分)
阅读以下说明和 C 程序,将应填入 (n) 处的字句写在答题纸的对应栏内。
第6题:
()阅读下列说明和C语言程序,将应填入 (n)处的语句写在答题纸的对应栏内。[说明]下面程序是一个带参数的主函数,其功能是显示在命令行中输入的文本文件内容。[C语言函数]#include"stdio.h"main(argc,argv) int argc; char *argv[]; { (1) ; if((fp=fopen(argv[1],”r’’))== (2) ) { printf(”file not open!\n”);exit(0);} while( (3) ) putchar( (4) ); (5); }