问答题下列给定程序中,函数fun的功能是进行数字字符转换。若形参ch中是数字字符‘0’~‘9’,则将‘0’转换成‘9’,‘1’转换成‘8’,‘2’转换成‘7’,…,‘9’转换成‘0’;若是其他字符则保持不变;并将转换后的结果作为函数值返回。
请在程序的下画线处填入正确的内容并将下画线删除,使程序得出正确的结果。
注意:部分源程序给出如下。
不得增行或删行,也不得更改程序的结构!
试题程序:
#include<stdio.h>
/*********found*********/
【1】
fun(char ch)
{
/*********found*********/
if(ch>='0'&&
【2】
)
/*********found*********/
return'9'-(ch-
【3】
);
return ch;
}
main()
{ char c1,c2;
printf("\nThe result:\n");
c1='2';c2=fun(c1);
printf("c1=%c c2=%c\n",c1,c2);
c1='8';c2=fun(c1);
printf("cl=%c c2=%c\n",c1,c2);
c1='a'; c2=fun(c1);
printf("c1=%c c2=%c\n",c1,c2);
}
问答题编程题
下列程序定义了N×N的二维数组,并在主函数中赋值。请编写函数fun(),函数的功能是:求出数组周边元素的平方和并作为函数值返回给主函数中的s。例如:若a 数组中的值为
a=0 1 2 7 9
1 11 21 5 5
2 21 6 11 1
9 7 9 10 2
5 4 1 4 1
则返回主程序后s的值应为310。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
#include
#include
#include
#define N 5
int fun (int w[][N])
{
}
main()
{
int a[N][N]={0,1,2,7,9,1,11,21,5,5,2,21,6,11,1,9,7,9,10,2,5,4,1,4,1};
int i, j;
int s;
clrscr();
printf("*****The array*****/n ");
for (i=0; i
问答题编写函数fun,它的功能是:求小于形参n同时能被3与7整除的所有自然数之和的平方根,并作为函数值返回。例如,若n为1000时,程序输出应为:s=153.909064。注意:部分源程序在文件PROG1.C中。请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。试题程序:#include<math.h>#include<stdio.h>double fun(int n){}main()/*主函数*/{ void NONO()j printf("S=%f\n",fun(1000)); NONO();}void NONO(){/*本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。*/ FILE*fp,*wf; int i,n ; double s; fp=fopen("in.dat","r"); wf=fopen("out.dat","W"); for(i=0;i<10;i++){ fscanf(fp,"%d",&n); s=fun(n); fprintf(wf,"%f\n",s); } fclose(fp); fclose(wf);}
问答题学生的记录由学号和成绩组成,N名学生的数据已放入主函数中的结构体数组s中。请编写函数fun,其功能是:按分数降序排列学生的记录,高分在前,低分在后。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
试题程序:
#include <stdio.h>
#define N 16
typedef struct
{
char num[10];
int s;
}STREC;
void fun(STREC a[])
{
}
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", 66},
{"GA017", 64}, {"GA018", 64},
{"GA016", 72}};
int i;
fun(s);
printf("The data after sorted: /n");
for(i=0; i<N; i++)
{
if(i% 4==0)
/*每行输出4个学生记录* /
printf("/n");
printf("% s % 4d", s[i].num, s[i].s);
}
printf("/n");
}
问答题请编写函数fun(),它的功能是计算:s=(1-ln(1)-ln(2)-ln(3)-…-ln(m))2 s作为函数值返回。 在C语言中可调用log(n)函数求ln(n)。log函数的引用说明是double log(double x)。 例如,若m的值为15,则fun()函数值为723.570801。 注意:部分源程序给出如下。 请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。 试题程序: #include <conio.h> #include <stdio.h> #include <math.h> double fun(int m) main() clrscr(); printf("%f/n",fun(15));
问答题下列给定程序中函数fun的功能是:用递归算法计算斐波拉契数列中第n项的值。从第1项起,斐波拉契数列为:1,1,2,3,5,8,13,21,… 请改正程序中的错误,使它能得出正确结果。 注意:不要改动mam函数,不得增行或删行,也不得更改程序的结构! 试题程序: #include < stdio.h > long fun (int g) /**********found********** / switch (g); case 0 :return 0; /**********found********** / case 1; case 2 : return 1; return (fun (g-1)+fun (g-2)); void main () long fib; int n; printf ("Input n:"); scanf ("% d", &n); printf ("n=%d/n", n); fib=fun (n); printf(" fib=% d/n/n", fib);
问答题编写函数fun,它的功能是计算下列级数和,和值由函数值返回。
例如,当n= 10,x=0.3时,函数值为1.349859。
注意:部分源程序在文件PROG1.C文件中。
请勿改动主函数mam和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
#include
#include
double fun (double x , int n)
{
}
main()
{void NONO ();
printf("%f/n", fun(0.3,10));
NONO();
}
void NONO ()
{/*本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。*/
FILE *fp,*wf ;
int i,n ;
double S,X ;
fp=fopen ("in.dat","r");
wf = fopen ("out.dat","w");
for(i=0 ; i < 10 ; i++) {
fscanf (fp, "%lf,%d", &x, &n);
s = fun (x, n);
fprintf (wf, "%f/n", s);
}
fclose( fp);
fclose (wf); }
问答题
假定输入的字符串中只包含字母和*号。请编写函数fun,它的功能是:除了尾部的*号之外,将字符串中其他*号全部删除。形参p已指向字符串中最后的一个字母。在编写函数时,不得使用C语言提供的字符串函数。
例如,字符串中的内容为:***A*BC*DEF*G*******,删除后,字符串中的内容应当是:ABCDEFG*******。
注意:部分源程序在文件PROG1.C中。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
#include <stdio.h>
void fun(char *a, char *p)
{
}
main()
{ char s[81],*t;
void NONO();
printf("Enter a string:/n");gets(s);
t=s;
while (*t) t++;
t--;
while (*t=="*")t--;
fun(s, t);
printf("The string after deleted:/n");puts(s);
NONO();
}
void NONO()
{/* 本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。 */
FILE *in, *out;
int i; char s[81],*t;
in=fopen("in.dat","r");
out=fopen("out.dat","w");
for(i=0; i<10; i++) {
fscanf(in, "%s", s);
t=s;
while (*t) t++;
t--;
while (*t=="*")t--;
fun(s, t);
fprintf(out, "%s/n", s);
}
fclose (in);
fclose (out);
}
问答题给定程序中,函数fun的功能是:统计形参s所指字符串中数字字符出现的次数,并存放在形参t所指的变量中,最后在主函数中输出。例如,形参s所指的字符串为:abcdef35adgh3kjsdf7。输出结果为:4。
请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。
注意:源程序存放在
下的BLANK1.C中。
不得增行或删行,也不得更改程序的结构!
#include<stdio.h>
void fun(char*s, int*t)
{int i, n;
n=0;
/**********found**********/
for(i=0; ______ !=0; i++)
/**********found**********/
if(s[i]>="0"
/**********found**********/
______;
}
main()
{ char s[80]="abcdef35adgh3kjsdf7";
int t;
printf("/nThe original string is: %s/n", s);
fun(s,
printf("/nThe result is: %d/n", t);
}
问答题下列给定程序中函数fun()的功能是:用递归算法计算斐波拉契数列中第n项的值。从第1项起,斐波拉契数列为:1,1,2,3,5,8,13,21,…
例如,若给n输入7,则该项的斐波拉契数值为13。
请改正程序中的错误,使它能得出正确结果。
注意:不要改动main()函数,不得增行或删行,也不得更改程序的结构!
试题程序:
#include<stdio.h>
long fun(int g)
{
//****found****
switch(g);
{
case 0: return 0;
//****found****
case 1: case 2: return 1;
}
return(fun(g-1)+fun(g-2));
}
void main()
{
long fib; int n;
printf("Input n:");
scanf("%d",
printf("n=%d/n", n);
fib=fun(n);
printf("fib=%d/n/n", fib);
}
问答题给定程序中,函数fun的功能是:计算形参x所指数组中N个数的平均值(规定所有数均为正数),作为函数值返回;并将大于平均值的数放在形参y所指数组中,在主函数中输出。
例如,有10个正数:46 30 32 40 6 17 45 15 48 26,平均值为:
30.500000
主函数中输出:46 32 40 45 48
请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。
注意:源程序存放在考生文件夹下的BLANK1.C中。不得增行或删行,也不得更改程序的结构!
给定源程序:
#include
#define N 10
double fun(double x[],double *y)
{ int i,j; double av;
/**********found**********/
av=__1__;
/**********found**********/
for(i=0; i
for(i=j=0; i
/**********found**********/
if(x[i]>av) y[__3__]= x[i];
y[j]=-1;
return av;
}
main()
{ int i; double x[N],y[N];
for(i=0; i4.0f ",x[i]);}
printf("/n");
printf("/nThe average is: %f/n",fun(x,y));
for(i=0; y[i]>=0; i++) printf("%5.1f ",y[i]);
printf("/n");
}
问答题下列给定程序中,函数fun的功能是:求出s所指字符串中最后一次出现的t所指字符串的地址,并通过函数值返回,在主函数中输出从此地址开始的字符串;若未找到,则函数值为NULL。 例如,当字符串中的内容为“abcdabfabcdx”,t中内容为“ab”时,输出结果应是“abcdx”。 当字符串中的内容为“abcdabfabcdx”,t中内容为“abd”时,则程序输出未找到信息“not be found!”。 请改正程序中的错误,使它能得出正确的结果。 注意:不要改动main函数,不得增行或删行,也不得更改程序的结构! 试题程序:#include < stdlib.h >#include < stdio.h >#include < conio.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;}void main(){ char s[100],t[100],*p; system("CLS"); printf("/nPlease enterstring s:"); scanf("%s",s); printf("/nPlease entersubstring t:"); scanf("%s",t); p=fun(s,t); if(p) printf("/nThe result is:%s/n",p); else printf("knNot found!/n");}
问答题下列给定程序中,函数proc()的功能是:判断一个整数m是否是素数,若是返回1,否则返回0。在main()函数中,若proc()返回1,则输出YES,若proc()返回0,则输出NO!
请修改程序中的错误,使它能得出正确的结果。
注意:不要改动main()函数,不得增行或删行,也不得更改程序的结构。
试题程序:
#include<stdlib.h>
#include<conio.h>
#include<stdio.h>
int proc(int m)
{ int k=2;
while(k<=m
else return 0;
}
void main()
{ int n;
system("CLS");
printf("/nPlease enter n: ");
scanf("%d",
if(proc(n)) printf("YES/n");
else printf("NO!/n");
}
问答题下列程序中,函数fun的功能是:按顺序给S所指数组中的元素赋予从2开始的偶数,然后再按顺序对每5个元素求平均值,并将这些值依次存放在W所指的数组中。若S所指数组中元素的个数不是5的倍数,则多余部分忽略不计。 例如,S所指数组有14个元素,则只对前lO个元素进行处理,不对最后的4个元素求平均值。 请改正程序中的错误,使它能得出正确的结果。 注意:不要改动main函数,不得增行或删行,也不得更改程序的结构! 试题程序: #include<stdio.h> #define SIZE 20 fun(double*s,double*w) int k,i;double sum;. for(k=2,i=0;i<SIZE;i++) (s[il=k;k+=2; /********found********/ sun=0.0; for(k=0,i=0;i<SIZE;i++) (sum+=s[i]; /********found********/ if(i+1%5==0) [w[k]=sum/5;sum=0;k++;) return k; main() (double a[SIZE],b[SIZE/5]; int i,k; k=fun(a,b); printf("The original data:/n"); for(i=0;i<SIZE;i++) if(i%5==0)printf("/n"); printf("%4.0"a[i]); printf("/n/nThe result:/n"); for(i=0;i<k;i++) printf("%6.2f",b[i]; printf("/n/n");
问答题给定程序中,函数fun的功能是将带头结点的单向链表逆置。即若原链表中从头至尾结点数据域依次为:2、4、6、8、10,逆置后,从头至尾结点数据域依次为:10、8、6、4、2。
请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。
注意:源程序存放在考生文件夹下的BLANK1.C中。
不得增行或删行,也不得更改程序的结构!
#include
#include
#define N 5
typedef struct node {
int data;
struct node *next;
} NODE;
void fun(NODE *h)
{NODE *p, *q, *r;
/********** found**********/
P = h->【1】;
/********** found**********/
if (p==【2】__) return;
q = p->next;
p->next = NULL;
while (q)
{ r = q->next; q->next = p;
/********** found**********/
p = q; q =【3】;
}
h->next = p;
}
NODE *creatlist(int a[])
{NODE *h,*p,*q; int i;
h= (NODE *)malloc(sizeof(NODE));
h->next = NULL;
for(i=0; idata=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]={2,4,6,8,10};
head=creatlist(a);
printf("/nThe original list:/n");
outlist(head);
fun(head);
printf("/nThe list after inverting:
/n");
outlist(head) ;
}
问答题请编写函数fun,函数的功能是:将M行N列的二维数组中的数据,按列的顺序依次放到一维数组中。函数fun中给出的语句仅供参考。
例如,二维数组中的数据为:
33 33 33 33
44 44 44 44
55 55 55 55
则一维数组中的内容应是:
33 44 55 33 44 55 33 44 55 33 44 55。
请勿改动主函数main和其它函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
给定源程序:
#include<stdio.h>
void fun(int s[][10],int b[],int *n,int mm,int nn)
{
/*以下代码仅供参考*/
int i,j,np=0;/*np用作b数组下标*/
*n=np;
}
main()
{int w[10][10]={{33,33,33,33},{44,44,44,44},{55,55,55,55}},i,j;
int a[100]={0},n=0;
printf("The matrix:/n");
for(i=0;i<3;i++]
{for(j=0;j<4;j++)printf("%3d",w[i][j]);
printf("/n");
}
fun(w,a,
printf("The A array:/n");
for(i=0;i<n;i++)printf("%3d",a[i]);
printf("/n/n");
}
问答题下列给定程序中proc()函数的功能是:将n个无序整数按从小到大排序。
请修改程序中的错误,使它能得出正确的结果。
注意:不要改动main()函数,不得增行或删行,也不得更改程序的结构。
试题程序:
#include<conio.h>
#include<stdlib.h>
#include<stdio.h>
void proc(int n,int *arr)
{
int i, j, p, t;
for(j=0; j<n-1; j++)
{
p=j;
//****found****
for(i=j+1; i<n-1; i++)
if(arr[p]>arr[i])
//****found****
t=i;
if(p!=j)
{t=arr[j]; arr[j]=arr[p]; arr[p]=t; }
}
}
void putarr(int n, int*z)
{
int i;
for(i=1; i<=n; i++, z++)
{
printf("%4d", *z);
if(!(i%10)) printf("/n");
}
printf("/n");
}
void main()
{ int arr[20]={9, 3, 0, 4, 1, 2, 5, 6, 8, 10, 7},
n=11;
system("CLS");
printf("/n/nBefore sorting %d numbers:
/n", n); putarr(n, arr);
proc(n, arr);
printf("/nAfter sorting %d numbers:
/n", n); putarr(n, arr);
}
问答题m个人的成绩存放在score数组中,请编写函数fun,它的功能是将低于平均分的人数作为函数值返回,将低于平均分的分数放在below所指的数组中。
例如,当score数组中的数据为10、20、30、40、50、60、70、80、90时,函数返回的人数应该是4,below所指的数组中的数据应为10、20、30、40。
注意:部分源程序存在文件PROG1.C中。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入编写的若干语句。
给定源程序如下。
#include<stdio.h>
#include<string.h>
int fun(int score[],int m,int below[])
{
}
main()
{ int i,n,below[9];
int score[9]={10,20,30,40,50,60,70,80,90);
n=fun(score,9,below);
printf("/nBelow the average score are:");
for(i=0;i<n;i++)printf("%d",below[i]);
}
问答题编写函数fun,其功能是:将两个两位数的正整数a、b合并成一个整数放在c中。合并的方式是:将a数的十位和个位数依次放在c数的十位和千位上,b数的十位和个位数依次放在c数的百位和个位上。
例如,当a=45,b=12时,调用该函数后,c=5142。
注意:部分源程序给出如下。数据文件IN.DAT中的数据不得修改。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入编写的若干语句。
试题程序:
#include <stdlib.h>
#include <stdio.h>
#include <conic.h>
void fun(int a,int b,long*c)
{
}
void main()
{
int a,b;
long c;
system("CLS");
printf("Input a,b;");
scanf("%d%d",
fun(a,b,
printf("The result is:%ld\n",c);
}
问答题给定程序MODI1.C中函数 fun 的功能是:判断ch中的字符是否与str所指串中的某个字符相同; 若相同,什么也不做,若不同,则将其插在串的最后。
请改正程序中的错误,使它能进行正确的操作。
注意:不要改动 main 函数,不得增行或删行,也不得更改程序的结构!
给定源程序:
#include
#include
/**********found**********/
void fun(char str, char ch )
{ while ( *str
/**********found**********/
if ( *str == ch )
{ str [ 0 ] = ch;
/**********found**********/
str[1] = '0';
}
}
main( )
{ char s[81], c ;
printf( "/nPlease enter a string:/n" ); gets ( s );
printf ("/n Please enter the character to search : " );
c = getchar();
fun(s, c) ;
printf( "/nThe result is %s/n", s);
}
