问答题请编写函数void fun(int x, int pp[], int *n),它的功能是:求出能整除x且不是偶数的各整数,并按从小到大的顺序放在即所指的数组中,这些除数的个数通过形参n返回。 例如,若x中的值为30,则有4个数符合要求,它们是1, 3,5,15。 注意:部分源程序给出如下。 请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。 试题程序: #include <conio.h> #include <stdio.h> void fun (int x, int pp[], int *n) main() int x,aa[1000], n, i ; clrscr(); printf("/nPlease enter an integer number : /n ") ; scanf ("%d", fun (x, aa, for (i=0 ; i<n ; i++) printf ("%d ", aa [i]); printf ("/n ") ;
问答题请编写函数fun,其功能是:计算并输出3~n之间(含3和n)所有素数的平方根之和。 例如,在主函数中从键盘为n输入100后,输出为:sum=148.874270。 [注意] 要求n的值大于2但不大于100。 [注意] 部分源程序给出如下。请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。 [试题源程序] #include<math.h> #include<stdio.h> double fun(int n) main() int n; double sum; printf("/n/nInput n:"); scanf("%d", &n); sum=fun(n); printf("kn/nsum=%f/n/n", sum);
问答题给定程序中,函数fun的功能是:利用指针数组对形参ss所指字符串数组中的字符串按由长到短的顺序排序,并输出排序结果。ss所指字符串数组中共有N个字符串,且串长小于M。 请在程序的下画线处填入正确的内容并把下画线删除,使程序得出正确的结果。注意:不得增行或删行,也不得更改程序的结构! 试题程序:#inelude<stdio.h>#include<string.h>#deftne N 5#deftne M 8void fun(char(*ss)[M]){ char*ps[N],*tp;int i,j,k; for(i=0;i<N;i++) ps[i]=ss[i]; for(i=0;i<N一1;i++) {/******found******/ k=___1___; for(j=i+1;j<N;j++)/******found******/ if(strlen(ps[k])<strlen(__2__)) k=j; [i] tp=ps[j]; ps[i]=ps[k];/******found******/ ps[k]=___3___; } prinff(“\nThe string after sorting by length:\n\n”)for(i=0;i<N;i++)puts(ps[i]);}main(){char eh[N][M]={“red”,“green”,“blue”,“yellow”,“black”}; int i; printf(“\nThe origin-1 string\n\n”); for(i=0;i<N;i++)puts(ch[i]); printf(“\n”); fun(oh);}
问答题请编写一个函数,函数的功能是删除字符串中的所有空格。
例如, 主函数中输入"asd af aa z67", 则输出为 "asdafaaz67"。
注意:部分源程序在文件PROG1.C中。
请勿改动主函数main和其它函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
给定源程序:
#include
#include
int fun(char *str)
{
}
main()
{
char str[81];
int n;
printf("Input a string:") ;
gets(str);
puts(str);
fun(str);
printf("*** str: %s/n",str);
NONO();
}
问答题给定程序中,函数fun的功能是将带头结点的单向链表逆置。即若原链表中从头至尾结点数据域依次为:2、4、6、8、10,逆置后,从头至尾结点数据域依次为:10、8、6、4、2。 请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。 注意:源程序存放在考生文件夹下的BLANK1.C中。 不得增行或删行,也不得更改程序的结构!1 #include<stdio.h>2 #include<stdlib.h>3 #define N 54 typedef struct node{5 int data;6 struct node *next;7 } NODE;8 void fun(NODE *h)9 { NODE *p,*q,*r;10 /**********found**********/11 p=h->___1___;12 /**********found**********/13 if(p==__2__)return;14 q=p->next;15 p->next=NULL;16 while(q)17 { r=q->next;q->next=p;18 /**********found**********/19 p=q;q=__3__ ;20 }21 h->next=p;22 }23 NODE *creatlist(int a[])24 { NODE *h,*p,*q;int i;25 h=(NODE *)malloc(sizeof(NODE));26 h->next=NULL;27 for(i=0;i<N;i++)28 { q=(NODE *)malloc(sizeof(NODE));29 q->data=a[i];30 q->next=NULL;31 if(h->next==NULL)h->next=p=q;32 else{p->next=q;p=q;}33 }34 return h;35 }36 void outlist(NODE *h)37 { NODE *p;38 p=h->next;39 if(p==NULL)printf(''The 1ist is NULL!\n'');40 else41 { printf(''\nHead'');42 do43 { printf(''->%d”,p->data);p=p->next;}44 while(p!=NULL);45 printf(''->End\n'');46 }47 }48 main()49 { NODE *head;50 int a[N]={2,4,6,8,10};51 head=creatlist(a);52 printf(''\nThe original list:\n'');53 outlist(head);54 fun(head);55 printf(''\nThe list after inverting:\n¨);56 outlist(head);57 }
问答题假定输入的字符串中只包含字母和*号。请编写函数fun,它的功能是:只删除字符串前导和尾部的*号,串中字母之间的*号都不删除。形参n给出了字符串的长度, 形参h给出了字符串中前导*号的个数,形参e给出了字符串中最后*号的个数。在编写函数时,不得使用C语言提供的字符串函数。
例如,字符串中的内容为:****A*BC*DEF*G*******,删除后,字符串中的内容应当是:A*BC*DEF*G。
注意: 部分源程序在文件PROG1.C文件中。请勿改动主函数main和其它函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
给定源程序:
#include
void fun( char *a, int n,int h,int e )
{
}
main()
{ char s[81],*t,*f; int m=0, tn=0, fn=0;
printf("Enter a string:/n");gets(s);
t=f=s;
while(*t){t++;m++;}
t--;
while(*t=='*'){t--;tn++;}
while(*f=='*'){f++;fn++;}
fun( s , m,fn,tn );
printf("The string after deleted:/n");puts(s);
NONO();
}
问答题给定程序MODI1.C中函数fun的功能是:将s所指字符串中位于奇数位置的字符或ASCII码为偶数的字符放入t所指数组中(规定第一个字符放在第0位中)。 例如,字符串中的数据为:AABBCCDDEEFF,则输出应当是:ABBCDDEFF。 请改正函数fun中指定部位的错误,使它能得出正确的结果。 注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!#include <stdio.h>#include <string.h>#define N 80void fun(char *s, char t[]){ int i, j=0;for(i=0; i<(int)strlen(s);i++)/***********found***********/if(i%2 /***********found***********/t[i]='/0';}main (){ char s[N], t[N] ;printf("/nPlease enter string s : "); gets (s);fun (s, t);printf("/nThe resultis : %s/n",t); }
问答题给定程序MODI1.C中 fun 函数的功能是:分别统计字符串中大写字母和小写字母的个数。
例如, 给字符串 s 输入:AAaaBBb123CCccccd,则应输出结果:
upper = 6, lower = 8。
请改正程序中的错误,使它能计算出正确的结果。
注意:不要改动 main 函数,不得增行或删行,也不得更改程序的结构!
给定源程序:
#include
/**********found**********/
void fun ( char *s, int a, int b )
{
while ( *s )
{ if ( *s >= 'A'
s++;
}
}
main( )
{ char s[100]; int upper = 0, lower = 0 ;
printf( "/nPlease a string : " ); gets ( s );
fun ( s,
printf( "/n upper = %d lower = %d/n", upper, lower );
}
问答题编写函数fun,其功能是:将所有大于1小于整数m的非素数存入xx所指数组中,非素数的个数通过k返回。 注意:部分源程序给出如下。 请勿改动主函数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", &n); fun (n, &m, zz); printf ("/n/nThere are % d non- prime numbers less than % d:", m, n); for(n=0; n<m; n++) printf("/n % 4d", zz[n]);
问答题程序定义了N×N的二维数组,并在主函数中自动赋值。请编写函数fun,函数的功能是:使数组右上三角元素中的值乘以m。例如:若m的值为2,a数组中的值为则返回主程序后a数组中的值应为注意:部分源程序存在文件PROG1.C中。请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入编写的若干语句。给定源程序如下。#include<stdio.h>#include<stdlib.h>#defineN5voidfun(inta[][N],intm){}main(){inta[N][N],m,i,j;printf("*****Thearray*****/n");for(i=0;i<N;i++){for(j=0;j<N;j++){a[i][j]=rand()%20;printf("%4d",a[i][j]);}printf("/n");}dom=rand()%10;while(m>=3);printf("m=%4d/n",m);fun(a,m);printf("THERESULT/n");for(i=0;i<N;i++){for(j=0;j<N;j++)printf("%4d",a[i][j]);printf("/n");}}
问答题函数fun的功能是:将a、b中的两个正整数合并形成一个新的整数放在c中。合并的方式是:将a中的十位和个位数依次放在变量c的十位和千位上,b中的十位和个位数依次放在变量c的个位和百位上。
例如,当a=45,b=12。调用该函数后,c=5241。
注意:部分源程序给出如下。
请勿改动main函数和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
试题程序:
#include<stdio.h>
void fun(int a,int b,long*c)
{
}
main()
{inc a,b;long c;
printf("Input a,b:");
scanf("%d%d",&a,&b);
fun(a,b,&c);
printf("The result is:%ld/n",c);
}
问答题给定程序中,函数fun的功能是:找出形参s所指字符串中出现频率最高的字母(不区分大小写),并统计出其出现的次数。
例如,形参s所指的字符串为:abcAbsmaxless,程序执行后的输出结果为:
letter'a':3times
letter's':3times
请在程序的下画线处填入正确的内容并把下画线删除,使程序得出正确的结果。
注意:部分源程序在文件BLANK1.C中。
不得增行或删行,也不得更改程序的结构!
试题程序:
#include
#include #include void fun(char,lc S) {int k[2 6]=f 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<k[n])max=M; ) printf("\nAfter count:\n"); for(i=0 ; i<26;i++) if(k[i]==max) printf("\nletter\'%c\':%dtimes\n",i+'a',k[i]); } main() { char s[81]; printf("\nEnter a string:\n\n"); gets(s); fun(s); }
问答题下列给定程序中函数fun的功能是:通过某种方式实现两个变量值的交换,规定不允许增加语句和表达式。 例如,变量a中的值原为8,b中的值原为3,程序运行后a中的值为3,b中的值为8。 请改正程序中的错误,使它得出正确的结果。 注意:不要改动main函数,不得增行或删行,也不得更改程序的结构! 试题程序:#include < stdlib.h >#include < conio.h >#inclucle < stdio.h >int fun(int*x,int y){ int t;/*********found*********/ t=x;x=y;/*********found*********/ return(y)=}void main(){ int a=3,b=8; system("CLS"); printf("%d%d/n",a,b); b=fun(&a,b); printf("%d%d/n",a,b);}
问答题请编写函数fun,该函数的功能是:统计一行字符串中单词的个数,作为函数值返回。字符串在主函数中输入,规定所有单词由小写字母组成,单词之间有若干个空格隔开,一行的开始没有空格。
注意:请勿改动main函数和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
#include<string.h>
#include<stdio.h>
#define N 80
int fun(char *s)
{
}
void main()
{
FILE * wf;
char line[N];
int num=0;
printf("Enter a string:/n");
gets(line);
num=fun(line);
printf("The number of wordis:%d/n/n",num);
/*********found*********/
wf=fopen("out.dat","w");
fprintf(wf,"%d",fun("a bigcar"));
fclose(wf);
/*********found*********/
}
问答题N名学生的成绩已在主函数中放入一个带有头结点的链表结构中,h指向链表的头结点。请编写函数fun(),其功能是:找出学生的最高分,并由函数值返回。
注意:部分源程序给出如下。
请勿改动main()函数和其他函数中的任何内容,仅在函数fun()的花括号中填入所编写的若干语句。试题程序:
#include<stdio.h>
#include<stdlib.h>
#define N 8
struct slist
{
double s;
struct slist*next;
};
typedef struct slist STREC;
double fun(STREC*h)
{
}
STREC*creat(double*s)
{
STREC*h,*p,*q;
int i=0;
h=p=(STREC*)malloc(sizeof(STREC));
p->s=0;
while(i<N)
//产生8个结点的链表,各分数存入链表中
{
q=(STREC*)malloc(sizeof(STREC));
p-->s=s[i];i++;p->next=q;
p=q;
}
p->next=NULL;
return h; //返回链表的首地址
}
void outlist(STREC*h)
{
STREC*p;
p=h;
prinrf("head");
do{
printf("->%2.0f",p->s);
p=p->next;
}
//输出各分数
while(p->next!=NULL);
printf("/n/n");
}
void main()
{
double s[N]={85,100,99,85,91,72,64,87},max;
STREC*h;
h=creat(s);
outlist(h);
max=fun(h);
printf("max=%6.1f/n",max);
}
问答题请编写函数fun,其功能是计算并输出如下多项式的值。
S
n
=1+1/1!+1/2!+1/3!+1/4!+…+1/n!
例如,若主函数从键盘给n输入15,则输出为S=2.718282。
注意:n的值要求大于1但不大于100。部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
试题程序:
#include<stdio.h>
double fun(int n)
{
}
main()
{
int n;
double s;
printf("Input n:");
scanf("%d",
s=fun(n);
printf("S=%f/n", s);
}
问答题给定程序中,函数fun的功能是:判断形参s所指字符串是否是"回文"(Palindrome),若是,函数返回值为1;不是,函数返回值为0。"回文'是正读和反读都一样的字符串(不区分大小写字母)。
例如,LEVEL和Level是'回文",而LEVLEV不是"回文"。
请在程序的下画线处填入正确的内容并把下画线删除,使程序得出正确的结果。
注意:部分源程序在文件BLANK1.C中。
不得增行或删行,也不得更改程序的结构!
试题程序:
#include<stdio.h>
#include<string.h>
#include<ctype.h>
int fun(char*s)
{ char*lp,*rp;
/*********found*********/
lp=
【1】
;
rp=s+strlen(s)-1;
while((toupper(*ip)==toupper
(*rp))&&(lp<rp)){
/*********found*********/
lp++;rp
【2】
;}
/*********found*********/
if(lp<rp)
【3】
;
else return 1;
}
main()
{char s[81];
printf("Enter a string:");
scanf("%s",s);
if(fun(s))
printf("\n\"%s\’is a Palindrome.\n\n”,s);
else
printf(“\n\"%s\"isn't a Palindrome.\n\n",s);
}
问答题编写函数fun,其功能是:求ss所指字符串中指定字符的个数,并返回此值。例如,若输入字符串123412132,输入字符为1,则输出3。注意:部分源程序在文件PROG1.C中。清勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。 #include<stdio.h> #include<string.h> #define M 81 int fun(char*ss,charc) { } main() { char a[M],ch; void NONO(); printf(“\nPlease enter a string:”);gets(a); printf(“\nPlease enter a char:”);ch=getchar(); printf(“\nThe number of the char is:%d\n”,fun(a,ch)); NONO(); } void NONO() {/*本函数用于打开文件,输入测试数据,调用fun函数,输出数据,关闭文件。*/ int i; FILE*rf,*wf; char a[M],h[M],ch; rf=fopen(“in.dat”,“r”); wf:fopen(“out.dat”,“w”); for(i=0;i<10;i++) { fscanf(rf,“%s”,a); fscanf(rf,“%s”,b); ch=*b: fprintf(wf,“%c=%d\n”,ch,fun(a,ch)); } fclose(rf); fclose(wf); }
问答题学生的记录由学号和成绩组成,N名学生的数据已放入主函数中的结构体数组s中,请编写函数fun,其功能是:把分数最高的学生数据放在b所指的数组中。注意:分数最高的学生可能不止一个,函数返回分数最高的学生人数。注意:部分源程序给出如下。请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。试题程序: #include<stdio.h> #define N 16 typedef struct { char num[10]; int s; }STREC; int fun(STREC*a,STREC*b) { } void main() { STREC S[N]={{"GA005",85},{"GA003",76},{"GA002",69},{"GA004",85},{"GA001",91},{"GA007",72},{"GA008",64},{"GA006",87},{"GA015",85},{"GA013",91},{"GA012",64},{"GA014",91},{"GA011",77},{"GA017",64},{"GA018",64},{"GA016",72}}; STREC h[N]; int i,n; n=fun(s,h); printf("The%d highest score:\n",n); for(i=0 ;i<n;i++) printf("%s%4d\n",h[i].num,h[i].s);/*输出最高分学生的学号和成绩*/ printf("\n");}
问答题给定程序MODI1.C中函数fun的功能是:求出以下分数序列的前n项之和,和值通过函数值返回到main函数。例如,若n=5,则应输出8.391667。请改正程序中的错误,使它能计算出正确的结果。注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!给定源程序:#include<stdio.h>/************found************/voidfun(intn){inta,b,c,k;doubles;s=0.0;a=2;b=1;for(k=1;k<=n;k++){/************found************/s=s+(Double)a/b;c=a;a=a+b;b=c;}returns;}main(){intn=5;printf("/nThevalueoffunctionis:%lf/n",fun(n));}
