填空题下列给定程序中函数fun的功能是:逐个比较p、q所指两个字符串对应位置上的字符,并把ASCII值大或相等的字符依次存放到c所指的数组中,形成一个新的字符串。
例如,若主函数中a字符串为“aBCDeFgH”,b字符串为“Abcd”,则c中的字符串应为“aBcdeFgH”。
请改正程序中的错误,使它能得出正确的结果。
注意:部分源程序在文件MODI1.C中,不得增行或删行,也不得更改程序的结构!
#include <stdio.h>
#include <string.h>
void fun(char *p,char *q,char*c)
{
/* * * * * * * * * * * *found* * * * * * * * * * * */
int k=1;
/* * * * * * * * * * * *found* * * * * * * * * * * */
while(*p!=*q)
{if(*p<*q)c[k]=*q;
else c[k]=*p;
if(*p)p++;
if(*q) q++;
k++;
}
}
main( )
{char a[10]="aBCDeFgH",b[10]="ABcd",c[80]={"/0"};
fun(a,b,c);
printf("The string a:");puts(a);
printf("The string b:");puts(b);
printf("The result:");puts(c);
}
填空题对长度为10的线性表进行冒泡排序,最坏情况下需要比较的次数为______。
填空题以下程序段打开文件后,先利用fseek函数将文件位置指针定位在文件末尾,然后调用ftell函数返回当前文件位置指针的具体位置,从而确定文件长度,请填空。 FILE*myf;longfl; myf= 【15】 ("test.t","rb"); fseek(myf,(),SEEK_END) fl+ftell(myf); fclose(myf); printf("%ld/n",fl);
填空题请补充函数proc(),该函数的功能是:删去一维数组中所有相同的数,使之只剩一个。数组中的数已按由小到大的顺序排列,函数返回删除后数组中数据的个数。
例如,若一维数组中的数据是:1 1 2 2 2 3 4 4 5 5 6 6 6 7 7 8 10 10。
删除后,数组中的内容应该是:1 2 3 4 5 6 7 8 10。
注意:部分源程序给出如下。
请勿改动main()函数和其他函数中的任何内容,仅在函数proc()的横线上填入所编写的若干表达式或语句。
试题程序:
#include<stdio.h>
#define M 80
int proc(int arr[], int n)
{
int i, t, j=0;
t=arr[0];
for(i=1; i<n; i++)
if(______)
;
else
{
______;
t=arr[i];
}
arr[j++]=t;
return j;
}
void main()
{
int arr[M]={1, 1, 2, 2, 2, 3, 4, 4, 5, 5, 6, 6, 6, 7, 7, 8, 10, 10}, i, n=18;
printf("The original data: /n");
for(i=0; i<n; i++)
printf("%4d", arr[i]);
n=proc(arr, n);
printf("/n/nThe data after deleted; /n");
for(i=0; i<n; i++)
printf("%4d", arr[i]);
printf("/n");
}
填空题下面程序把从终端读入的文本(用@作为文本结束标志)输出到一个名为bi.dat的新文件中,请填空。
#include "stdio.h"
FILE *fp;
main()
{ char ch;
if((fp=fopen({{U}} 【16】 {{/U}}))==NULL)exit(0);
while((ch=getchar())!='@')fputc(ch ,fp);
fclose(fp);
}
填空题已定义char ch="$";int i=1,j;执行j=!ch&&i++以后,i的值为______。
填空题变量i、j、k已定义为int型并均有初值0,用以下语句进行输入时:
scanf("%d", &i); scanf("%d", &j); scanf("%d", &k);
从键盘输入:
12.3<CR> (<CR>代表Enter键)
则变量i、j、k的值分别是______、______、______。
填空题若有如下定义: int x=2,y=3,z=4; 则表达式!(x=y)||x+z&&y-z的值是 【9】 。
填空题下列程序的输出结果是{{U}} 【8】 {{/U}}。
main()
{ int a=1,b=2;
a=a+b;b=a-b,a=a-b;
printf("%d,%d/n",a,b) ;
}
填空题下述函数用于统计一行字符中的单词个数,单词之间用空格分隔。
word num (str)
char str[];
{int i,num=0,word=0;
for(i=0;str[i]!={{U}} 【15】 {{/U}};i++)
if({{U}} 【16】 {{/U}}==)word=0;
else if(word==0)
{
word=1;
{{U}} 【17】 {{/U}};
}
return(num);
}
填空题以下程序运行后的输出结果是{{U}} 【8】 {{/U}}。
#include <stdio.h>
main()
{ int a=1,b=3,c=5;
if (c=a+b) printf("yes/n");
else printf("no/n");
}
填空题若变量已正确定义,在执行以下while语句时,输入字符A后,ch的值是______。
while(ch=getchar()=='A');
填空题在面向对象方法,类之间共享属性和方法的机制称为______。
填空题有以下程序
#include
main()
{ int a[3][3]={{1,2,3},{4,5,6},{7,8,9}};
int b[3]={0},i;
for(i=0;i<3;i++) b[i]=a[i][2]+a[2][i];
for(i=0;i<3;i++) printf("%d",b[i]);
printf("/n");
}
程序运行后的输出结果是 【 】 。
填空题下面程序由两个源程序文件:t4.h和t4.c组成,程序编译运行结果是______。t4.h的源程序为:#define N 10#define f2(x) (x*N)t4.c的源程序为:#include#define M 8#define f(x) ((x)*M)#include "t4.h"main() int i,j; i=f(1+1); j=f2(1+1); printf("%d%d/n",i,j);
填空题在对文件操作的过程中,若要求文件的位置指针回到文件的开始处,应当调用的函数是 【9】 。
填空题有以下程序:
main()
{ int n=0,m=1,x=2;
if(!n) x-=1;
if(m) x-=2;
if(x) x-=3;
printf("%d/n",x);
}
执行后输出的结果是{{U}} 【9】 {{/U}}。
填空题以下程序运行后输出结果是 【20】 。 #include <stdio, h> main( ) int a,b,c; a=10; b:20; c=(a%b<1) ‖ (a/b>1); printf("%d %d %d/n",a,b,c);
填空题以下isprime函数的功能是判断形参a是否为素数,如果是素数,函数返回1,否则返回0。 int isprime( int a) int i; for(i =2;i<= a/2;i ++ ) if(a%i==0){{U}} {{/U}};{{U}} {{/U}};
填空题若从键盘输入58,则以下程序输出的结果是
________
。
main()
{ int a;
scanf("%d",&a);
if(a>50)printf("%d",a);
if(a>40)printf("%d",a);
if(a>30)printf("%d",a);}
