问答题给定程序中,函数fun的功能是:将形参n中,各位上为偶数的数取出,并按原来从高位到低位的顺序组成一个新的数,并作为函数值返回。
例如,从主函数输入一个整数:27638496,函数返回值为:26846。
请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。
注意:源程序存放在考生文件夹下的BLANK1.C中。
不得增行或删行,也不得更改程序的结构!
#include
unsigned long fun (unsigned long n)
{ unsigned long x=0,s,i; int t;
s=n;
1=____1____ ;
while ( ____2____ )
if (t%2==0) {
}
s=s/10;
}
return x;
}
main ()
{ unsigned long n=—1;
while (n>99999999 ||n<0)
{ printf("Please input (0
问答题下列给定程序中函数fun的功能是:用冒泡法对6个字符串进行升序排列。
请改正程序中的错误,使它能得出正确的结果。
注意:不得增行或删行,也不得更改程序的结构!
#include<stdio.h>
#include<string.h>
#define MAXLINE 20
fun(char*pstr[6])
{int i,j;
char*p;
for(i=0;i<5;i++){
/**************found**************/
for(j=i+1,j<6,j++)
{
if(strcmp(*(pstr+i),*(pstr+j))>0)
{
p=*(pstr+i);
/**************found**************/
*(pstr+i)=pstr+j;
*(pstr+j)=p;
}
}
}
}
main()
{int i;
char*pstr[6],str[6][MAXLINE];
for(i=0;i<6;i++)pstr[i]=str[i];
printf("/nEnter 6 string(1 string at each line):/n");
for(i=0;i<6;i++)scanf("%s",pstr[i]);
fun(pstr);
printf("The strings after sorting:/n");
for(i=0;i<6;i++)printf("%s/n",pstr[i]);
}
问答题编写函数fun,其功能是:求ss所指字符串中指定字符的个数,并返回此值。 例如,若输入字符串”123412132”,输入字符为”1”,则输出3。 注意:部分源程序已给出。 请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。 试题程序: #include<stdlib.h> #include<conio.h> #include<stdio.h> #define M 81 int fun(char*ss,char c) int i=0; for(;*ss!='/0';ss++) if(*ss==c) i++;/*求出ss所指字符串中指 定字符的个数*/ return 1: void main() char a[M],ch; system("CLS"); printf("/n Please enter a string:"); gets(a); printf("/nPlease enter a char:"); ch=getchar(); printf("/nThe number of the char is:%d/n",fun(a,ch));
问答题printf("The result is:%f/n " , s);
问答题规定输入的字符串只包含字母和*号。请编写函数fun,它的功能是:将字符串中的前导*号全部删除,中间和尾部的*号不删除。例如,字符串中的内容为:*******A*BC*DEF*G****,删除后,字符串中的内容应当是:A*BC*DEF*G****。在编写函数时,不得使用C语言提供的字符串函数。 注意:部分源程序在文件PROG1.C中。 请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。#include <stdio.h>void fun(char *a){}main (){ char s[81];void NONO () ;printf("Enter a string:/n"); gets (s);fun(s); printf ("The string after deleted:/n");puts (s); NONO () ;}void NONO(){/* 本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。 */FILE *in, *out ;int i ; char s[81] ;in = fopen("in.dat","r");out = fopen("out.dat","w");for(i = 0 ; i < 10 ; i++) {fscanf(in, "%s", s);fun (s);fprintf(out, "%s/n", s) ; }fclose(in); fclose(out); }
问答题编写函数fun,其功能是:将所有大于1小于整数m的非素数存入xx所指数组中,非素数的个数通过k返回。
例如,若输入17,则应输出:4 6 8 9 10 12 14 15 16。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
试题程序:
#include<stdlib.h>
#include<conio.h>
#include<stdio.h>
void fun(int m,int *k,int xx[])
{
}
void main()
{
int m,n,zz[100];
system("CLS");
printf("/nPlease enter an integer number between 10 and 100:");
scanf("%d",
fun(n,
printf("/n/nThere are %d non-prime numbers less than %d:",m,n);
for(n=0;n<m;n++)
printf("/n%4d",zz[n]);
}
问答题下列给定程序中,函数fun的功能是:对N名学生的学习成绩,按从高到低的顺序找出前m(m≤10)名学生来,并将这些学生的数据存放在一个动态分配的连续存储区中,此存储区的首地址作为函数值返回。 请改正程序中的错误,使它能得出正确的结果。 注意:不要改动mmn函数,不得增行或删行,也不得更改程序的结构! 试题程序:#include < stdlib.h >#include < conio.h >#include < string.h >#include < stdio.h >#include < malloc.h >#define N 1 0typedef struct ss{ char hum[10]; int s;}STU;STU*fun(STU a[],int m){ STU b[N],*t; int i,j,k;/*********found*********/ * t=calloc(m,sizeof(STU)) for(i=0;i < N;i++) b[i]=a[i]; for(k=0;k < m;k++) { for(i=j=0; i < N;i++) if(b[i].s >b[j].s) j=i;/*********found*********/ t[k].num=b[j].num; b[j].s=0; } return t;}outresult(STU a[],FILE*Pf){ int i; for(i=0;i < N;i++) fprintf(pf,"No=%s Mark=%d/n",a[i].num,a[i].s); fprintf(pf,"/n/n");}void main(){ STU a[N]={{"A01",81},{"A02",89},{"A03",66},{"A04",87}, {"A05",77},{"A0 6",90},{"A07",79},{"A08",61},{"A0 9", 80},{"A10",71}}; STU*pOrcler; int i,m; system("CLS"); printf("****THE Original data****/n"); outresult(a,stdout); printf("/nGive the number of the students who have better scoEe:"); scanf("%d",&m); while(m >10) { printf("/riGire the r1Llmbet of the students who havebetter score:"); scanf("%d",&m);} porder=fun(a,m); printf("****THE RESULT****/n"); printf("The top:/n"); for(i=0;i < m;i++) printf("%S%d/r1",porder[i].result,pOrder[i].s); free(pOrder);}
问答题请编写函数proc(),其功能是:计算并输出下列多项式值。
S=(1+1/2)+(1/3+1/4)+…+(1/(2n-1)+1/2n)
例如,若输入10,则输出为S=3.597740。
n的值要求大于1但不大于100。
注意:部分源程序给出如下。
请勿改动函数main()和其他函数中的任何内容,仅在函数proc()的花括号中填入所编写的若干语句。
试题程序:
#include<stdio.h>
double proc(int n)
{
}
void main()
{
int n;
double s;
printf("/nInput n:");
scanf("%d",
s=proc(n);
printf("/ns=%f/n", s);
}
问答题给定程序MODI1.C中函数fun()的功能是:根据整型形参m,计算如下公式的值。例如,若m=2000,则应输出0.000160。请改正程序中的语法错误,使它能计算出正确的结果。注意:不要改动main()函数,不得增行或删行,也不得更改程序的结构。#include<stdio.h>/**********found**********/fun(intm)doubley=0,d;inti;/**********found**********/for(i=100,i<=m,i+=100)d=(double)i*(double)i;y+=1.0/d;return(y);main()intn=2000;printf("/nTheresultis%lf/n",fun(n));
问答题给定程序中已建立一个带有头结点的单向链表,链表中的各结点按数据域递增有序链接。函数fun的功能是:删除链表中数据域值相同的结点,使之只保留一个。
请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。
注意:源程序存放在考生文件夹下的BLANK1.C中。不得增行或删行,也不得更改程序的结构!
给定源程序:
#include
#include
#define N 8
typedef struct list
{ int data;
struct list *next;
} SLIST;
void fun( SLIST *h)
{ SLIST *p, *q;
p=h->next;
if (p!=NULL)
{ q=p->next;
while(q!=NULL)
{ if (p->data==q->data)
{ p->next=q->next;
/**********found**********/
free(___1___);
/**********found**********/
q=p->___2___;
}
else
{ p=q;
/**********found**********/
q=q->___3___;
}
}
}
}
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("/nThe list is NULL!/n");
else
{ printf("/nHead");
do { printf("->%d",p->data); p=p->next; } while(p!=NULL);
printf("->End/n");
}
}
main( )
{ SLIST *head; int a[N]={1,2,2,3,4,4,4,5};
head=creatlist(a);
printf("/nThe list before deleting :/n"); outlist(head);
fun(head);
printf("/nThe list after deleting :/n"); outlist(head);
}
问答题下列给定程序中,函数fun的功能是:在形参ss所指字符串数组中,将所有串长超过k的字符串中后面的字符删除,只保留前面的k个字符。ss所指字符串数组中共有N个字符串,且串长小于M。
请在程序的下画线处填入正确的内容并将下画线删除,使程序得出正确的结果。
注意:部分源程序给出如下。
不得增行或删行,也不得更改程序的结构!
试题程序:
#include<stdio.h>
#include<string.h>
#define N 5
#define M 10
/*********found*********/
void fun(char(*ss)
【1】
,int k)
{ int i=0;
/*********found*********/
while(i<
【2】
){
/*********found*********/
SS[i][k]=
【3】
;i++;)
}
main()
{ char x[N][M]={"Create","Modify","Sort","skip","Delete");
int i;
printf("\nThe original string\n\n");
for(i=0;i<N;i++)puts(x[i]);
printf("\n"),
fun(x,4);
printf("\nThe string after deleted:\n\n");
for(i=0;i<N;i++)
puts(x[i]);
printf("\n");
}
问答题下列给定程序中,函数fun的功能是:给定n个实数,输出平均值,并统计平均值以上 (含平均值)的实数个数。例如,n=8时,输入193.199、195.673、195.757、196.051、196.092、196.596、196.579、196.763、所得平均值为195.838745,在平均值以上的实数个数应为5。 请改正程序中的错误,使其能得出正确的结果。 注意:部分源程序在文件MOD11.C中,不要改动main函数,不得增行或删行,也不得更改程序的结构! 试题程序::I}ir1clude < stdlib.h >#include < conio.h >#include < stdio.h >int fun(float x[],int r1)/*********found*********/ int j,c=0 ; float xa=0.0; for(j=0;j < n;j++) xa+=x[j]/n;printf("ave=%f/r1",xa);for(j=0;j < n ; j++)/*********found*********/ if(x[j] = >xa) c++; return c;}main(){float x[100]={193.199,195.673,195.757,196.051,196.092,196.596,196.579,196.763); system("cls"); printf("%d/n",fun(x,8));}
问答题
给定程序MODI1.C中函数fun的功能是:删除p所指字符串中的所有空白字符(包括制表符、回车符及换行符)。
输入字符串时用"#"结束输入。
请改正程序中的错误,使它能输出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!
#include<string.h>
#include<stdio.h>
#include<ctype.h>
fun(char *p)
{int i, t; char c[80];
/**********found**********/
For(i=0, t=0; p[i]; i++)
if(!isspace(*(p+i))) c[t++]=p[i];
/**********found**********/
c[t]="/0";
strcpy(p, c);
}
main()
{char c, s[80];
int i=0;
printf("Input a string:");
c=getchar();
while(c!="#")
{s[i]=c; i++; c=getchar();}
s[i]="/0";
fun(s);
puts(s);
}
问答题请编写函数fun,功能是:判断形参n中的正整数是几位数(输入数据的位数不超过4位),并将结果通过函数值返回。 例如:若输入的数据为123,则输出结果为:输入的数字是3位。 注意:部分源程序存在PROG1.C中,请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。#include <stdio.h>void NONO();int fun(int n){}main(){int n,place;do{printf(”请输入一个4位以内的正整数:");scanf("%d",&n); } while(n<0 ‖ n>9999); place=fun(n); printf("输入的数字是%d位\n",place); NONO();}void NONO()(/*本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。*/ FILE *fp,*wf; int i,n,place;fp=fopen("in.dat","r");wf=fopen("out.dat","w"); for(i=0;i<10;i++) (fscanf(fp,"%d",&n); place=fun(n); fprintf(wf,"%d\n",place); } fclose(fp); fclose(wf);}
问答题下列给定程序中,函数fun的功能是:实现两个整数的交换。例如,给a和b分别输入60和65,输出为:a=65 b=60。请改正程序中的错误,使它能得出正确的结果。注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。试题程序:#include<stdio.h>#include<conio.h>#include<stdlib.h>/*********found*********/void fun(int a,b){ int t;/*********found*********/ t=b;b=a;a=t ;}void main(){ int a,b; system("CLS"); printf("Enter a,b:"); scanf("%d%d",&a,&b); fun(&a,&b); printf("a=%d b=%d\n",a,b);}
问答题下列给定程序中,函数fun的功能是:用下面的公式求π的近似值,直到最后一项的绝对值小于指定的数(参数hum)为止。例如,程序运行后,输入0.0001,则程序输出3.1414。请改正程序中的错误,使它能得出正确的结果。注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!试题程序:#include<math.h>#include<stdio.h>floatfun(floatnun)ints;floatn,t,pi;t=1;pi=0;n=1;s=1;/****************found***********/while(t>=num)pi=pi+t;n=n+2;s=-s;/******************found***************/t=s%n;pi=pi*4;returnpi;voidmain()floatn1,n2;system("CLS");printf("Enterafloatnumber:");scanf("%f",&n1);n2=fun(n1);printf("%6.4f/n",n2);
问答题给定程序MODI1.C中函数fun的功能是:逐个比较p、q所指两个字符串对应位置中的字符,把ASCII值大或相等的字符依次存放到c所指数组中,形成一个新的字符串。
例如,若主函数中a字符串为:aBCDeFgH,主函数中b字符串为:ABcd,则c中的字符串应为:aBcdeFgH。
请改正程序中的错误,使它能得出正确结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
给定源程序:
#include
#include
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);
}
问答题下列给定程序中,函数fun的功能是:从整数10到55之间,查找能被3整除且有一位上的数值是5的数,把这些数放在b所指的数组中,这些数的个数作为函数值返回。规定函数中a1放个位数,a2放十位数。请改正程序中的错误,使它能得出正确的结果。注意:部分源程序在文件MOD11.C中,不得增行或删行,也不得更改程序的结构!#nclude<stdio.h>intfun(int*b){int k,a1,a2,i=0;for(k=10;k<=55;k++){/**********found**********/a2=k/100;al=k一a2*10;if((k%3==0&&a2==5)‖(k%3==0&&a1==5)){b[i]=k;i++;}}/**********found**********/return k;}main(){int a[100],k,m;m=fun(a);printf(''The result is:\n'');for(k=0;k<m;k++)printf(''%4d'',a[k]);printf(''\n'');}
问答题由N个有序整数组成的数列已放在一维数组中,下列给定程序中,函数fun的功能是:利用折半查找法查找整数m在数组中的位置。若找到,返回其下标值;否则,返回-1。 折半查找的基本算法是:每次查找前先确定数组中待查的范围low和high(low(high),然后用m与中间位置(mid)上元素的值进行比较。如果m的值大于中间位置元素的值,则下一次的查找范围落在中间位置之后的元素中;反之,下一次的查找范围落在中间位置之前的元素中。直到low>hjgh,查找结束。 请改正程序中的错误,使它能得出正确的结果。 注意:不要改动main函数,不得增行或删行,也不得更改程序的结构! 试题程序: #include<stdio.h> #define N 10 /********found********/ void fun(int all,int m) int low=0,high=N-1,mid; while(low<=high) mid=(low+high)/2; if(m<a[mid]) high=mid-1; /********found********/ else If(m>a[mid]) low=mid+1; else return(mid); return(-1); main() int i,a[N]=(-3,4,7,9,13,45,67,89,100,180],k,m; printf("a数组中的数据如下:"); for(i=0;i<N;i++) printf("%d",a[i]); printf("Enter m:"); scanf("%d", k=fun(a,m); if(k>=0) printf("m=%d,index=%d/n",m,k); else printf("Not be found!/n");
问答题请编写函数fun(),该函数的功能是:移动一维数组中的内容,若数组中有n个整数,要求把下标从p到n-1(p≤n-1)的数组元素平移到数组的前面。
例如,一维数组中的原始内容为1,2,3,4,5,6,7, 8,9,10,11,12,13,14,15,p的值为6。移动后,一维数组中的内容应为7,8,9,10,11,12,13,14,15,1,2,3,4,5,6。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
#include<stdio.h>
#define N 80
void fun(int *w,int p,int n)
{
}
main()
{
int a[N]={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
int i,p,n=15;
printf("The original data:/n");
for(i=0;i<n;i++)
printf("%3d",a[i]);
printf("/n/nEnter p:");
scanf("%d",&p);
fun(a,p,n);
printf("/nThe data after moving:/n");
for(i=0;i<n;i++)
printf("%3d",a[i]);
printf("/n/n");
}
