问答题给定程序中,函数fim的功能是:计算出形参s所指字符串中包含的单词个数,作为函数值返回。为便于统计,规定各单词之间用空格隔开。
例如,形参s所指的字符串为:This is a C language program.,函数的返回值为6。
请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。
注意:源程序存放在考生文件夹下的BLANK1.C中。
不得增行或删行,也不得更改程序的结构!
#include
int fun(char *s)
{ int n=0, flag=0;
while(*s!='/0')
{ if(*s!=' ' flag=l;}
/********** found**********/
if (*s==' ') flag= 【2】 ;
/********** found**********/
【3】 ;
}
return n;
}
main ()
{ char str[81]; int n;
printf("/nEnter a line text:/n");
gets (str);
n=fun(str);
printf("/nThere are %d words in
this text./n/n",n);
}
问答题
函数fun的功能是:将a、b中的两个两位正整数合并形成一个新的整数放在c中。合并的方式是:将a中的十位和个位数依次放在变量c的千位和十位上,b中的十位和个位数依次放在变量c的个位和百位上。
例如,当a=45,b=12。调用该函数后,c=4251。
注意:部分源程序存在文件PROG1.C中。数据文件IN.DAT中的数据不得修改。
请勿改动主函数main和其它函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
给定源程序:
#include<stdio.h>
void fun(int a, int b, long*c)
{
}
main()
{ int a, b; long c;
printf("Input a b:");
scanf("%d%d",
fun(a, b,
printf("The result is:%ld/n", c);
}
问答题下列给定程序中,函数fun的功能是:将s所指字符串中的字母转换为按字母序列的后续字母(如“Z”转化为“A”,“z”转化为“a”),其他字符不变。请改正程序中的错误,使它能得出正确的结果。注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!试题程序:#include<stdlib.h>#include<stdio.h>#include<ctype.h>#include<conio.h>void fun(char*s){/*********found*********/ while(*S!='@') { if(*S>='A'&&*s<='Z'‖*s>='a'&&*s<='z') { if(*s=='Z')*S='A'; else if(*s=='z')*S='a'; else *s+=1; } /*********found*********/ (*s)++; }}void main(){ char s[80]; system("CLS"); printf("\n Enter a st ring with length<80:\n\n"); gets(s); printf("\n The string:\n\n"); puts(s); fun(s); printf("\n\n The Cords:\n\n"); puts(S);}
问答题编写函数fun,其功能是:求出1~1000之间能被7或11整除,但不能同时被7和11整除的所有整数,并将其放在a所指的数组中,通过n返回这些数的个数。注意:部分源程序给出如下:,请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。试题程序:#include<stdlib.h>#include<conio.h>#include<stdio.h>void fun(int=}=a,int*n){)void main(){ int aa[1000],n,k; system("CLS"); fun(aa,&n); for(k=0;k<n;k++) if((k+1)%10==0) { printf("%5 d",aa[k]); printf("\n");)/*一行写9个数*/ else printf("%5d",aa[k]);}
问答题给定程序MODI1.C中函数fun的功能是:求出s所指字符串中最后一次出现的t所指子字符串的地址,通过函数值返回,在主函数中输出从此地址开始的字符串;
若未找到,则函数值为NULL。
例如,当字符串中的内容为“abcdabfabcdx”,t中的内容为“ab”时,输出结果应是:abcdx。
当字符串中的内容为“abcdabfabcdx”,t中的内容为“abd”时,则程序输出未找到信息:notbe found!。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
#include<stdio.h>
#include<string.h>
char*fun(char*s,char*t)
{
char*p,*r,*a;
/**********found**********/
a=Null;
while(*s)
{P=s;r=t;
while(*r)
/**********found**********/
if(r==P)
{r++;p++;)
else break;
if(*r=="/0")a=s;
s++:
}
return a;
}
main()
{
char s[100],t[100],*p;
printf("/nPlease enter string S:");scanf("%s",s);
printf("/nPlease enter substring t:");scanf("%s",t);
P=fun(s,t);
if(p)printf("/nThe result is:%s/n",p);
else printf("/nNot found!/n");
}
问答题已知一个数列从第0项开始的前三项分别为0,0,1,以后的各项都是其相邻的前三项之和。给定程序MODI1. C中函数fun的功能是:计算并输出该数列前n项的平方根之和。n的值通过形参传入。
例如,当n=10时,程序的输出结果应为:23.197745。
请改正程序中的错误,使程序能输出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!
#include <stdio. h>
#include <math. h>
/************found************/
fun(int n)
{ double sum, s0, s1, s2, s; int k;
sum=1.0;
if(n<=2) sum=0.0;
s0=0.0; s1=0.0; s2=1.0;
for (k=4; k<=n; k++)
{ s=s0+s1+s2;
sum+=sqrt(s);
s0=s1; s1=s2; s2=s;
}
/************found************/
return sum
}
main( )
{int n;
printf("Input N=");
scanf("%d",
printf("%f/n", fun(n));
}
问答题请编写函数fun,函数的功能是:将放在字符串数组中的M个字符串(每串的长度不超过N),按顺序合并组成一个新的字符串。 例如,字符串数组中的M个字符串为 AAAA BBBBBBB CC 则合并后的字符串的内容应是:AAAABBBBBBBCC。 提示:strcat(a,b)的功能是将字符串b复制到字符串a的串尾上,成为一个新串。 注意:部分源程序在文件PROG1.C中。 请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。1 #include<stdio.h>2 #include<string.h>3 #define M 34 #define N 205 void fun(char a[M][N],char *b)6 {78 }9 main()10 { char w[M][N]={''AAAA'',''BBBBBBB'',''CC''},a[100];11 int i;void NONO();12 printf(''The string:\n'');13 for(i=0 ; i<M;i++)puts(w[i]);14 printf(''\n'');15 fun(w,a);16 printf(''The A string:\n'');17 printf(''%s'',a);printf(''\n\n'');18 NONO();19 }20 void NONO()21 {/*请在此函数内打开文件,输入测试数据,调用fun函数,输出数据,关闭文件。*/22 FILE *rf,*wf ;23 char w[M][N],a[100];int i;24 rf=fopen(''in.dat'',''r'');25 wf=fopen(''out.dat'',''w'');26 for(i=0;i<10;i++) {27 fscanf(rf,''%s%s%s'',w [0],w[1], w [2]);28 fun(w,a);29 fprintf(wf,''%s\n'',a);30 }31 fclose(rf);fclose(wf);32 }
问答题给定程序MODI1.C中 fun 函数的功能是:求
s = aa… aa - ... - aaa - aa - a
(此处 aa… aa 表示 n 个 a, a 和 n 的值在 1 至 9 之间)
例如 a = 3, n = 6, 则以上表达式为:
s = 333333 - 33333 - 3333 - 333 - 33 - 3
其值是:296298
a 和 n 是 fun 函数的形参,表达式的值作为函数值传回 main函数。
请改正程序中的错误,使它能计算出正确的结果。
注意: 不要改动 main 函数,不得增行或删行,也不得更改程序的结构!
给定源程序:
#include
long fun (int a, int n)
{ int j ;
/**************found**************/
long s = 0, t = 1 ;
for ( j = 0 ; j < n ; j++)
t = t * 10 + a ;
s = t ;
for ( j = 1 ; j < n ; j++) {
/**************found**************/
t = t % 10 ;
s = s - t ;
}
return(s) ;
}
main( )
{ int a, n ;
printf( "/nPlease enter a and n:") ;
scanf( "%d%d",
printf( "The value of function is: %ld/n", fun ( a, n ) );
}
问答题给定程序中,函数fun的功能是将带头节点的单向链表结点数据域中的数据从小到大排序。即若原链表结点数据域从头至尾的数据为:10、4、2、8、6,排序后链表结点数据域从头至尾的数据为:2、4、6、8、10。
请在程序的下划线处填入正确的内容并把下划线删除, 使程序得出正确的结果。
注意:源程序存放在考生文件夹下的BLANK1.C中。不得增行或删行,也不得更改程序的结构!
给定源程序:
#include
#include
#define N 6
typedef struct node {
int data;
struct node *next;
} NODE;
void fun(NODE *h)
{ NODE *p, *q; int t;
/**********found**********/
p = __1__ ;
while (p) {
/**********found**********/
q = __2__ ;
while (q) {
/**********found**********/
if (p->data __3__ q->data)
{ t = p->data; p->data = q->data; q->data = t; }
q = q->next;
}
p = p->next;
}
}
NODE *creatlist(int a[])
{ NODE *h,*p,*q; int i;
h = (NODE *)malloc(sizeof(NODE));
h->next = NULL;
for(i=0; i
{ q=(NODE *)malloc(sizeof(NODE));
q->data=a[i];
q->next = NULL;
if (h->next == NULL) h->next = p = q;
else { p->next = q; p = q; }
}
return h;
}
void outlist(NODE *h)
{ NODE *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");
}
}
main()
{ NODE *head;
int a[N]= {0, 10, 4, 2, 8, 6 };
head=creatlist(a);
printf("/nThe original list:/n");
outlist(head);
fun(head);
printf("/nThe list after sorting :/n");
outlist(head);
}
问答题给定程序MODI1.C中函数fun的功能是:从低位开始取出长整型变量s中奇数位上的数,依次构成一个新数放在t中。高位仍在高位,低位仍在低位。 例如,当s中的数为:7654321时,t中的数为:7531。 请改正程序中的错误,使它能得出正确的结果。 注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!1 #include<stdio.h>2 /**********found**********/3 void fun(long s,long t)4 { long s1=10;5 *t=s%10;6 while(s>0)7 { s=s/100;8 *t=s%10 * s1+*t,9 /**********found**********/10 s1=s1*100;11 }12 }13 main()14 {long s,t;15 printf(''\nPlease enter s:''); scanf(''%ld'',&s);16 fun(s,&t);17 printf(''The result is:%1d\n'',t);18 }
问答题下列给定程序中,函数fun的功能是:统计形参s所指的字符串中数字字符出现的次数,并存放在形参c所指的变量中,最后在主函数中输出。 例如, 若形参s所指的字符串为“abcdef35adah3kjsdf7”,则输出结果为4。 请在下划线处填入正确内容并将下划线删除,使程序得出正确的结果。 注意:部分源程序给出如下。 不得增行或删行,也不得更改程序的结构! 试题程序: #include<stdio.h> void fun(char*s,int*t) int i,n; n=0; /********found********/ for(i=0; (1) =0;i++) /********found********/ if(s[il>='0' /********found********/ (3) main() char s[80]="abcdef35adgh3kjsdf7"; int t; printf("/nThe original string is:%s/n",s); fun(s, printf("/nThe result is:%d/n"t);
问答题给定程序modil.c的主函数中,将a、b、c三个结点链成一个单向链表,并给各结点的数据域赋值,函数fun()的作用是:累加链表结点数据域中的数据作为函数值返回。请改正函数fun中指定部位的错误,使它能得出正确的结果。注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。试题程序:#include<stdio.h>typedef struet list{int data;struet list*next;}LIST;int fun(UST*h){LIST*p;/**********found**********/int t;p=h;/**********found**********/while(*p){/**********found**********/t=t+p.data;p=(*p).next;}return t;}main(){LIST a,b,c,*h;a}data=34;b.data=51;c.data=87;C.next='\0';h=&a;a)next=&b;b.next=&c;printf("总和=%d\n",fun(h));}
问答题下列给定程序中已建立一个带头结点的单向链表,链表中的各结点按结点数据域中的数据递增有序链接。函数fun的功能是:把形参x的值放入一个新结点并插入链表中,使插入后各结点数据域中的数据仍保持递增有序。
请在程序的下画线处填入正确的内容并将下画线删除,使程序得出正确的结果。
注意:部分源程序给出如下。
不得增行或删行,也不得更改程序的结构!
试题程序:
#include<stdio.h>
#include<stdlib.h>
#define N 8
typedef struct list
{ int data;
struer liSt*next;
}SLIST;
void fun(SLIST *h,int x)
{ SLISTp,*q,*s;
s=(SLIST*)malloc(Sizeof (SLIST));
/*********found*********/
S->data=
【1】
;
q=h;
P=h->next;
while(p!=NULL&&x>p->data){
/*********found*********/
q=
【2】
;
p=p->next;
}
s->next=p;
/*********found*********/
q->next=
【3】
;
}
SLIST * creatlist(int*a)
{ SLIST*h,*P,*q;int i ;
h=P=(SLIST*)malloc(sizeof(SLIST));
for(i=0;i<N;i++)
{q=(SLIST*)malloc(sizeof(SLIST));
q->data=a[i];P->nexL=q;p=q;
}
p->nexL=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 X;
int a[N]={11,12,15,18,19,22,25,29);
head=treatlist(a);
printf("\nThe list before inserting:\n");
outlist(head);
printf("\nEnter a number: ");
scanf("%d",&x);
fun(head,x);
printf("\nThe list after inserting:\n");
outliSt(head);
}
问答题给定程序MODI1.C中函数fun的功能是: 依次取出字符串中所有数字字符, 形成新的字符串, 并取代原字符串。
请改正函数fun中指定部位的错误, 使它能得出正确的结果。
注意: 不要改动main函数, 不得增行或删行, 也不得更改程序的结构!
给定源程序:
#include
void fun(char *s)
{ int i,j;
for(i=0,j=0; s[i]!='\0'; i++)
if(s[i]>='0'
s[j]="\0";
}
main()
{ char item[80];
printf("\nEnter a string : ");gets(item);
printf("\n\nThe string is : \"%s\"\n",item);
fun(item);
printf("\n\nThe string of changing is : \"%s\"\n",item );
}
问答题请编—个函数float fun( double h),该函数的功能是:使变量h中的值保留两位小数,并对第三位进行四舍五入(规定h中的值为正数)。 例如,若h值为1234, 567,则函数返回1234. 570000;若h值为1234.564,则函数返回1234. 560000。 注意:部分源程序在文件PROG1.C中。 请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。 试题程序:#include < stdio.h >#include < coni < *h >#include < stdlib.h >float fun (float h ){}void main (){ FILE *wf; float a; system ("CLS") ; printf ("Enter a: ") ; scanf ("% f"f &a) ; printf "The original data is : ") ; printf ("% f/n/n", a) : printf ("The result:%f/n", fun(a));/*********found*********/wf = fopen "out.dat", "w") :fprintf (wf, "f% f", fun (8.32533));fclose (wf) ;/*********found*********/}
问答题下列给定程序中,函数fun的功能是:找出100一x(x≤999)之间各位上的数字之和为15的所有整数,并在屏幕输出;将符合条件的整数的个数作为函数值返回。
例如,当n值为500时,各位数字之和为15的整数有:159、168、177、186、195、249、258、267、276、285、294 、 339 、 348 、 357 、 366 、 375、384 、 393,429 、 438 、 447 、456、465、474、483、492,共有26个。
请在程序的下画线处填入正确的内容并将下画线删除,使程序得出正确的结果。
注意:部分源程序给出如下。
不得增行或删行,也不得更改程序的结构!
试题程序:
#include < stdio.h >
int fun(int x)
{ int n , s1 , s2 , s3 , t;
/*********found*********/
n=
【1】
;
t=100;
/*********found*********/
while(t < =
【2】
)
{s1=t%10;s2=(t/10)%10;
s3=t/100;
if(s1+s2+s3==1 5)
{printf("%d',t);
n++;
}
/*********found*********/
【3】
;
}
return n;
}
main()
{ int x=一1;
while(x >999 ||x < 0)
{printf("Please input(0 < x < =999):");
scanf("%d",&x);}
printf("/nThe resultis:%d/n",fun(x));
}
问答题下列给定程序的功能是:读入一个整数k(2≤k≤10000),输出它的所有质因子(即所有为素数的因子)。例如,若输入整数2310,则应输出:2,3,5,7,11。请改正程序中的错误,使它能得出正确的结果。注意:不要改动main函数,不得增行或删行,也不得更改程存的结构!试题程序:
问答题程序定义了N×N的二维数组,并在主函数中自动赋值。
请编写函数fun(int a[][N],int n),该函数的功能是使数组左下半三角元素中的值加上n。
例如:若n的值为3,a数组中的值为
a=2 5 4
1 6 9
5 3 7
则返回主程序后a数组中的值应为
5 5 4
4 9 9
8 6 10
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数full的花括号中填入所编写的若干语句。
试题程序:
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#define N 5
fun(int a[][N],int n)
{
}
main()
{
int a[N][N],n,i,j;
clrscr();
printf("***** The array *****/n");
for(i=0;i<N;i++)
/*产生—个随机5*5矩阵*/
{
for(j=0;j<N;j++)
{
a[i][j]=rand()%10;
printf("%4d",a[i][j]);
}
printf("/n");
}
do
n=rand()%10;
/*产生一个小于5的随机数n*/
while(n>=5);
printf("n=%4d/n",n);
fun(a,n);
printf("*****THE RESULT*****/n");
for(i=0;i<N;i++)
{
for(j=0;j<N;i++)
printf("%4d",a[i][j]);
printf("/n");
}
}
问答题请编写函数fun(),它的功能是:移动一维数组中的内容,若数组中有n个整数,要求把下标从0到p(含p,p<n-1)的数组元素平移到数组的最后。例如:一维数组中的原始内容为:1,2,3,4,5,6,7,8,9,10;p的值为3。移动后,一维数组中的内容应为: 5,6,7,8,9,10,1,2,3,4。部分源程序在文件PROG1.C中。请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
#include<stdiO.h>
#define N 80
void fun(int *w,int p,int n)
{
}
main()
{in[ a[N]={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
int i,p,n=15;
printf("The odginal data:/n");
for(i=0;i<n;i++)printf("%3d",a[i]);
printf("/nEnter p:");
scanf("%d",&p);
fun(a,p,n);
printf ("/n The data after moving:/n");
for(i=0;i<n;i++)printf("%3d”,a[i]);
}
问答题给定程序MODI1.C中函数fun的功能是:按顺序给s所指数组中的元素赋予从2开始的偶数,然后再按顺序对每五个元素求一个平均值,并将这些值依次存放在w所指的数组中。若s所指数组中元素的个数不是5的倍数,多余部分忽略不计。
例如,s所指数组有14个元素,则只对前10个元素进行处理,不对最后的4个元素求平均值。
请改正程序中的错误,使它能得出正确结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
#include
#define SIZE 20
fun (double *s, double *w)
{ int k,i; double sum;
for ( k=2,i=0;i
