单选题以下程序的输出结果是 void fun(float*p1,float*p2,float*s) s=(float*)calloc(1,sizeof(float)); *s=*p1+*p2++; main() float a[2]=1.1,2.2,b[2]=10.0,20.0,*s=a; fun(a,b,s); printf("%5.2f/n",*s);
单选题若有定义语句:int year=2009,*p=&year;,以下不能使变量year中的值增至2010的语句是( )。
单选题有如下程序:
#include <stdio.h>
main()
{
int i;
FILE* fp;
for(i=0; i<5; i++)
{
fp = fopen("output.txt","w");
fputc("A"+i,fp);
fclose(fp);
}
}
程序运行后,在当前目录下会生成一个output.txt文件,其内容是______。
单选题下列选项中,不能用做标识符的是______。
A._1234_
B._1_2
C.int_2_
D.2_int_
单选题有以下程序:程序运行后不能输出字符u的语句是()。
单选题以下叙述中错误的是 ______。
A.对于double类型数组,不可以直接用数组名对数组进行整体输入或输出
B.数组名代表的是数组所占存储区的首地址,其值不可改变
C.当程序执行中,数组元素的下标超出所定义的下标范围时,系统将给出“下标越界”的出错信息
D.可以通过赋初值的方式确定数组元素的个数
单选题有以下程序 main() int i; for(i=1;i<=40;i++) if(i++%5==0) if(++i%8==0) pfintf("%d",i); printf("/n"); 执行后的输出结果是 A) 5 B) 24 C) 32 D) 40
单选题若有条件表达式(exp)?a-:b++,则以下表达式和表达式(exp)完全等价的是______。
单选题某二叉树共有12个结点,其中叶子结点只有1个。则该二叉树的深度为(根结点在第1层)
单选题在多媒体计算机中,CD-ROM属于( )。
单选题下面程序的输出是______。 fun(char *s,int p1,int p2) char c; while(p1<p2) c=s[p1];s[p1]=s[p2];s[p2]=c;p1++;p2--; main() char a[]="ABCDEFG",k,*p; fun(a,0,2);fun(a,4,6); printf("%s/n ",
问答题给定程序中,函数fun的功能是:找出形参s所指字符串中出现频率最高的字母(不区分大小写),并统计出其出现的次数。
例如,形参s所指的字符串为:abcAbsmaxless,程序执行后的输出结果为:
letter 'a' : 3 times
letter 's' : 3 times
请在程序的下划线处填入正确的内容并把下划线删除, 使程序得出正确的结果。
注意:源程序存放在考生文件夹下的BLANK1.C中。不得增行或删行,也不得更改程序的结构!
给定源程序:
#include
#include
#include
void fun(char *s)
{ int k[26]={0},n,i,max=0; char ch;
while(*s)
{ if( isalpha(*s) ) {
/**********found**********/
ch=tolower(__1__);
n=ch-'a';
/**********found**********/
k[n]+= __2__ ;
}
s++;
/**********found**********/
if(max
}
printf("/nAfter count :/n");
for(i=0; i<26;i++)
if (k[i]==max) printf("/nletter /'%c/' : %d times/n",i+'a',k[i]);
}
main()
{ char s[81];
printf("/nEnter a string:/n/n"); gets(s);
fun(s);
}
问答题下列程序定义了M×M的二维数组,并在主函数中赋值。请编写函数proc(),函数的功能是:求出数组周边元素的平均值并作为函数值返回给主函数中的s。例如,若a数组中的值为:
a=0 1 2 3 4
5 9 7 4 5
4 3 8 3 6
3 5 6 8 7
2 1 0 9 8
则返回主程序后,s的值为3.750000。
注意:部分源程序给出如下。
请勿改动main()函数和其他函数中的任何内容,仅在函数proc()的花括号中填入所编写的若干语句。
试题程序:
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#define M 5
double proc(int w[][M])
{
}
void main()
{
int a[M][M]={0, 1, 2, 3, 4, 5, 9, 7, 4, 5, 4, 3, 8, 3, 6, 3, 5, 6, 8, 7, 2, 1, 0, 9, 8};
int i, j;
double s;
system("CLS");
printf("****The array****/n");
for(i=0; i<M; i++)
{for(j=0; j<M; j++)
{printf("%4d", a[i][j]); }
printf("/n");
}
s=proc(a);
printf("****THE RESULT****/n");
printf("The sum is: %1f/n", s);
}
问答题给定程序中,函数fun的作用是:不断从终端读入整数,由变量a统计大于0的个数,用变量c来统计小于0的个数,当输入0时结束输入,并通过形参pa和pb把统计的数据传回主函数进行输出。 请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。 注意:源程序存放在考生文件夹下的BLANK1.C中。 不得增行或删行,也不得更改程序的结构!1 #include<stdio.h>2 void fun(int *px,int *py)3 {4 /**********found**********/5 int___(1)___;6 scanf(''%d'',&k);7 /**********found**********/8 while___(2)__9 {if(k>0) a++;10 if(k<0)b++;11 /**********found**********/12 __(3)___;13 }14 *px=a;*py=b;}15 main()16 {int x,y;17 fun(&x,&y);18 printf(''x=%d y=%d\n'',x,y);19 }
问答题给定程序中,函数fun的功能是:统计出带有头结点的单向链表中结点的个数,存放在形参n所指的存储单元中。
请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。
注意:源程序存放在考生文件夹下的BLANK1.C中。不得增行或删行,也不得更改程序的结构!
给定源程序:
#include
#include
#define N 8
typedef struct list
{ int data;
struct list *next;
} SLIST;
SLIST *creatlist(int *a);
void outlist(SLIST *);
void fun( SLIST *h, int *n)
{ SLIST *p;
/**********found**********/
___1___=0;
p=h->next;
while(p)
{ (*n)++;
/**********found**********/
p=p->___2___;
}
}
main()
{ SLIST *head;
int a[N]={12,87,45,32,91,16,20,48}, num;
head=creatlist(a); outlist(head);
/**********found**********/
fun(___3___,
printf("/nnumber=%d/n",num);
}
SLIST *creatlist(int a[])
{ SLIST *h,*p,*q; int i;
h=p=(SLIST *)malloc(sizeof(SLIST));
for(i=0; i
{ q=(SLIST *)malloc(sizeof(SLIST));
q->data=a[i]; p->next=q; p=q;
}
p->next=0;
return h;
}
void outlist(SLIST *h)
{ SLIST *p;
p=h->next;
if (p==NULL) printf("The list is NULL!/n");
else
{ printf("/nHead ");
do
{ printf("->%d",p->data); p=p->next; }
while(p!=NULL);
printf("->End/n");
}
}
问答题下列给定程序中,函数proc()的功能是:首先把b所指字符串中的字符按逆序存放,然后将str1所指字符串中的字符和str2所指字符串中的字符,按排列的顺序交叉合并到str所指数组中,过长的剩余字符接在str所指数组的尾部。
例如,当str1所指字符串中的内容为ABCDEFG,str2所指字符串中的内容为1234时,str所指数组中的内容应该为A483C2D1EFG;而当str1所指字符串中的内容为1234,str2所指字符串中的内容为ABCEDFG时,str所指数组中的内容应该为1G2F3E4DCBA。
请修改程序中的错误,使它能得出正确的结果。
注意:不要改动main()函数,不得增行或删行,也不得更改程序的结构。
试题程序:
#include<stdlib.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
void proc(char*str1, char*str2, char*str)
{
int i, j; char ch;
i=0; j=strlen(str2)-1;
//****found****
while(i>j)
{
ch=str2[i]; str2[i]=str2[j]; str2[j]=ch;
i++; j--;
}
while(*str1 || *str2)
{
if(*str1){*str=*str1; str++; str1++; }
if(*str2){*str=*str2; str++; str2++; }
}
//****found****
*str=0;
}
void main()
{
char s1[100], s2[100], t[200];
system("CLS");
printf("/nEnter s1 string:");
scanf("%s", s1);
printf("/nEnter s2 string:");
scanf("%s", s2);
proc(s1, s2, t);
printf("/nThe result is: %s/n", t);
}
问答题请编写一个函数fun,它的功能是:比较两个字符串的长度(不得调用C语言提供的求字符串长度的函数),函数返回较长的字符串。若两个字符串长度相同,则返回第一个字符串。
例如,输入beijing<CR>shanghai<CR>(<CR>为回车键),函数将返回shanghai。
注意:部分源程序存在文件PROG1.C中。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入要编写的若干语句。
#include<stdio.h>
char*fun(char*s,char*t)
{
}
main()
{char a[20],b[20];
void NONO();
printf("Input 1 th string:");
gets(a);
printf("Input 2th string:");
gets(b);
printf("%s/n",fun(a,b));
NONO();
}
void NONO()
{/*本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。*/
FILE*fp,*wf;
int i;
char a[20],b[20];
fp=fopen("in.dat","r");
wf=fopen("out.daft,"w");
for(i=0;i<10;i++){
fscanf(fp,"%s%s",a,b);
fprintf(wf,"%s/n",fun(a,b));
}
fclose(fp);
fclose(wf);
}
问答题请编写函数fun,其功能是:找出一维整型数组元素中最大的值及其所在的下标,并通过形参传回。数组元素中的值已在主函数中赋予。 主函数中x是数组名,n是x中的数据个数,max存放最大值,index存放最大值所在元素的下标。 注意:请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入编写的若干语句。 试题程序: #include<stdlib.h> #include<stdio.h> #included time.h> void fun(int a[],int n,int*max,int*d) { } void main() { FILE *wf; int i,x[20],max,index,n=10; int y[20]={4,2,6,8,11,5}; srand((unsigned)time(NULL)); for(i=0;i<n;i++) { x[i]=rand()%50; printf("%4d",x[i]);/*输出一个随机数组*/ } printf("\n"); fun(x,n,&max,&index); printf("Max=%5d,Index=%4d\n",max,index); /************/ wf=fopen("out.dat","w"); fun(y,6,&max,&index); fprintf(wf,"Max=%5d,Index=%4d",max,index); fclose(wf); /************/ }
问答题函数fun()的功能是:将s所指字符串中除了下标为奇数,同时ASCII值也为奇数的字符之外,其余的所有字符都删除,串中剩余字符所形成的一个新串放在t所指的数组中。 例如,若s所指字符串中的内容为“ABCDEFG12345”,其中字符A的ASCII码值虽为奇数,但所在数组中的下标为偶数,因此必须删除;而字符1的ASCII码值为奇数,所在数组中的下标也为奇数,因此不应当删除,其他以此类推。最后t所指数组中的内容应是“135”。 #include<stdio.h> #include<string.h> void fun(char *s,char t[]) main() char s[100],t[100];void NONO(); printf("/nPlease enter string s:");scanf("%s",s); fun(s,t); printf("/nThe result is:%s/n",t); NONO();
问答题给定程序MODI1. C中,函数fun的功能是:在有n名学生,2门课成绩的结构体数组std中,计算出第1门课程的平均分,作为函数值返回。例如,主函数中给出了4名学生的数据,则程序运行的结果为:第1门课程的平均分是:76.125000
请改正函数fun中指定部位的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
#include <stdio. h>
typedef struct
{char num[8];
double score[2];
}STU;
double fun(STU std[], int n)
{int i;
/**********found**********/
double sum;
/**********found**********/
for(i=0; i<2; i++)
/**********found**********/
sum+=std[i]. score[1];
return sum/n;
}
main( )
{STU
std[]=("N1001", 76.5, 82.0, "N1002", 66.5, 73.0, N1005", 80.5, 66. 0, "N1006", 81.0, 56.0};
printf("第1门课程的平均分是: %1f/n", fun(std, 4));
}