问答题下列给定程序中函数fun的功能是:计算n!。例如,给n输入5,则输出120.000000。请改正程序中的错误,使它能得出正确的结果。注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!试题程序:#include<stdio.h>#include<conio.h>double fun(int n){ double result=1.0;/*********found*********/ if n==0 return 1.0 ; while(n>1&&n<170)/*********found*********/ result=n--; return result;}main(){ int n; printf("Input N:"); scanf("%d",&n); printf("\n\n%d!=%lf\n\n",n,fun(n));}
问答题下列给定程序中,函数fun的功能是:将s所指字符串中的所有数字字符移到所有非数字字符之后,并保持数字字符串和非数字字符串原有的次序。 例如,s所指的字符串为“def35adh3kjsdf7”,执行后结果为“defadhkjsdf3537”。 请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。 注意:部分源程序给出如下。 不得增行或删行,也不得更改程序的结构! 试题程序: #include<stldio.h> void fun(char*s) ( inf j,j=O,k=O; char tl[80],t2[80]; for(i=0;s[i]!='/0';i++) if(s[i]>='O' /********found********/ (1) ; else tl[k++]=s[i]; t2[j]=O; t1[k]=O; for(i=O;i<k;i++) /********found********/ (2) ; /********found********/ for(i=0;i< (3) ;i++) s[k+i]=t2[i]; main() char s[80)="ba3a54j7sd567sdffs"; printf("/nThe original string is%s/n,s); fun(s); printf("/nThe restult is%s/n,s);
问答题下列给定程序中已建立一个带头结点的单向链表,链表中的各结点按结点数据域中的数据递增有序链接。函数fun的功能是:把形参x的值放入一个新结点并插入链表中,使插入后各结点数据域中的数据仍保持递增有序。
请在程序的下画线处填入正确的内容并将下画线删除,使程序得出正确的结果。
注意:部分源程序给出如下。
不得增行或删行,也不得更改程序的结构!
试题程序:
#include < stdio.h >
#include < stdlib.h >
#define N 8
typedef struct list
{ int data;
stEUCt liSt*next;
}SLIST;
void fun(SLIST*h,int x)
{ SLIST*p,*q,*s;
s=(SLIST*)malloi(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,lc creatlist(int*a)
{ SLIST*h,*p,*q;int i;
h=p=(SLIST*)malloc(si—
zeof(SLIST));
for(i=0;i < N;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 x;
int a[N]={11,12,15,18,19,22,25,29};
head=creatlist(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);
}
问答题请编写函数proc(),该函数的功能是:将放在字符串数组中的M个字符串(每串的长度不超过N),按顺序合并组成一个新的字符串。
例如,若字符串数组中的M个字符串为:
ABCD
BCDEFG
CDEFGHI
则合并后的字符串内容应该是ABCDBCDEFGCDEFGHI。
注意:部分源程序给出如下。
请勿改动main()函数和其他函数中的任何内容,仅在函数proc()的花括号中填入所编写的若干语句。
试题程序:
#include<stdio.h>
#include<conio.h>
#define M 3
#define N 20
void proc(char arr[M][N], char*b)
{
}
void main()
{
char str[M][N]={"ABCD", "BCDEFG", "CDEFGHI"}, i;
char arr[100]={"##################"};
printf("The string: /n");
for(i=0; i<M; i++)
puts(str[i]);
printf("/n");
proc(str,arr);
printf("The A string: /n");
printf("%s", arr);
printf("/n/n");
}
问答题下列给定程序中,函数proc()的功能是:输出M行M列整数方阵,然后求两条对角线上的各元素之和并将其返回。
请修改程序中的错误,使它能得出正确的结果。
注意:不要改动main()函数,不得增行或删行。也不得更改程序的结构。
试题程序:
#include<stdlib.h>
#include<conio.h>
#include<stdio.h>
#define M 5
//****found****
int proc(int n, int xx[][])
{
int i, j, sum=0;
printf("/nThe%d x%d matrix:/n", M, M);
for(i=0; i<M; i++)
{
for(j=0; j<M; j++)
//****found****
printf("%4f", xx[i][j]);
printf("/n");
}
for(i=0; i<n; i++)
sum+=xx[i][i]+xx[i][n-i-1];
return(sum);
}
void main()
int arr[M][M]={{1, 4, 3, 2, 4}, {4, 6, 2, 5, 0}, {3, 5, 2, 0, 1}, {7, 0, 5, 7, 3}, {5, 3.1, 9, 2}};
system("CLS");
printf("/nThe sum of all elements on 2 diagnals is%d", proc(M, arr));
}
问答题已知学生的记录由学号和学习成绩构成,N名学生的数据已存入a结构体数组中。请编写函数fun,该函数的功能是:找出成绩最低的学生记录,通过形参返回主函数(规定只有一个最低分)。已给出函数的首部,请完成该函数。
注意:请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
试题程序:
#include<stdio.h>
#include<string.h>
#include<conio.h>
#include<stdlib.h>
#define N 10
typedef struct ss
{char num[10];
int s;
}STU;
fun(STU a[],STU*s)
{
}
void main()
{
FILE*wf;
STU a[N]={{"A01",81},{"A02",89},{"A03",66},{"A04",87},{"A05",77},{"A06",90},{"A07",79},{"A08",61},{"A09",80},{"A10",71}),m;
int i;
system("CLS");
printf("*****The originaldata*****/n");
for(i=0;i<N;i++)
printf("No=%s Mark=%d/n",a[i].num,a[i].s);
fun(a,
printf("****THE RESULT****/n");
printf("The lowest :%s, %d/n",m.num,m.s);
/******************/
wf=fopen("out.dat","w");
fprintf(wf,"%s,%d",m.num,m.s);
fclose(wf);
/******************/}
问答题规定输入的字符串中只包含字母和*号。请编写函数fun,其功能是:将字符串中的前导*号全部移到字符串的尾部。
例如,字符串中的内容为“*******A*BC*DEF*G****”,移动后,字符串中的内容应当是“A*BC*DEEF*G***********”。在编写函数时,不得使用C语言提供的字符串函数。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
试题程序:
#include<stdio.h>
#include<conio.h>
void fun(char*a)
{
}
main()
{
char s[81], *p;
char test[4][80]={"********A*BC*DEF*G****", "A******B*CD**EF*G*", "****A****G*", "*d**b**a**e*"};
int i;
printf("Enter a string:/n");
gets(s);
fun(s);
printf("The string after moveing:/n");
puts(s);
}
问答题给定程序中,函数fun的功能是:用函数指针指向要调用的函数,并进行调用。规定在
【2】
处使f指向函数f1,在
【3】
处使f指向函数f2。当调用正确时,程序输出:
x1=5.000000,x2=3.000000,x1*x1+x1*x2=40.000000。
注意:部分源程序在文件BLANK1.C中。不得增行或删行,也不得更改程序的结构!
试题程序:
#include<stdio.h>
double f1(double x)
{return X*x;}
double f2(double X,double y)
{return x*y;)
double fun(double a,double b)
{
/*********found*********/
【1】
(*f)();
double r1,r2;
/*********found*********/
f=
【2】
;
r1=f(a);
/*********found*********/
f=
【3】
;
r2=(*f)(a,b);
return r1+r2;
}
main()
{double x1=5,x2=3,r;
r=fun(x1,x2);
printf("\nx1=%f,x2=%f,
x1*x1+x1*x2=%f\n",x1,x2,r);
}
问答题给定程序MODI1.C中fun函数的功能是:根据整型形参m,计算如下公式的值。例如,若主函数中输入5,则应输出-0.283333。请改正函数fun中的错误或在横线处填上适当的内容并把横线删除,使它能计算出正确的结果。注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!1#include<stdio.h>2doublefun(intm)3{4doublet=1.0;5inti;6for(i=2;i<=m;i++)7/**********found**********/8t=1.0-1/i;9/**********found**********/10_____;11}12main()13{14intm;15printf(''\nPleaseenter1integernumbers:\n'');16scanf(''%d'',&m);17printf(''\n\nTheresultis%1f\n'',fun(m));18}
问答题给定程序MODI1.C中函数fun的功能是:按以下递归公式求函数值。
┌ 10 (n=1)
fun(n)=┥
└ fun(n-1)+2 (n>1)
例如,当给n输入5时,函数值为18;当给n输入3时,函数值为14。
请改正程序中的错误,使它能得出正确结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
给定源程序:
#include
/************found************/
fun ( n )
{ int c;
/************found************/
if(n=1)
c = 10 ;
else
c= fun(n-1)+2;
return(c);
}
main()
{ int n;
printf("Enter n : "); scanf("%d",
printf("The result : %d/n/n", fun(n));
}
问答题请编写一个函数void fun(char *tt,int pp[]),统计在tt字符串中“a”到“ z”26个字母各自出现的次数,并依次放在pp所指数组中。
例如:当输入字符串abcdefghabcdeabc后,程序的输出结果应该是:33322110000000000000000000
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
#include <conio.h>
#include <stdio.h>
void fun (char*tt, int pp[])
{
}
main()
{
char aa[1000];
int bb[26], k, n;
clrscr();
printf("/nPlease enter a char string: ") ;
scanf("%s",aa);
fun(aa,bb);
for (k=0 ;k<26 ; k++)
printf("%d ",bb[k]) ;
printf("/n ");
}
问答题下列给定程序中函数fun的功能是:从整数10到55之间,查找能被3整除且有一位上的数值是5的数,把这些数放在b所指的数组中,这些数的个数作为函数值返回。规定函数中a1放个位数,a2放十位数。
请改正程序中的错误,使它能得出正确的结果。
注意:不得增行或删行,也不得更改程序的结构!
#include<stdio.h>
int fun(int*b)
{int k,a1,a2,i=0;
for(k=10;k<=55;k++)
{
/************found************/
a2=k/10;
a1=k-a2*10;
if((k%3==0i++;}
}
/************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");
}
问答题下列给定程序中函数fun的功能是:求两个非零正整数的最大公约数,并作为函数值返回。例如,若num1和num2分别为49和21,则输出的最大公约数为7;若num1和hum2分别为27和81,则输出的最大公约数为27。请改正程序中的错误,使它能得出正确结果。注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!试题程序:#include<stdio.h>int fun(int a,int b){ int r,t; if(a<b){/*********found*********/ t=a;b=a;a;t; } r=a%b; while(r!=0) (a=b;b=r;r=a%b;)/*********found*********/ return(a);}void main(){ int hum1,hum2,a; printf ( "Input numl num2:"); scanf("%d%d",&hum1,&hum2); printf("num1=%d hum2=%d\n\n",num1,num2); a=fun(num1,num2); printf("The maximun common divisor is%d\n\n",a);}
问答题函数fun的功能是: 将s所指字符串中除了下标为奇数、同时ASCII值也为奇数的字符之外,其余的所有字符都删除,串中剩余字符所形成的一个新串放在t所指的数组中。
例如,若s所指字符串中的内容为:"ABCDEFG12345",其中字符A的ASCII码值虽为奇数,但所在元素的下标为偶数,因此必需删除;而字符1的ASCII码值为奇数,所在数组中的下标也为奇数,因此不应当删除,其它依此类推。最后t所指的数组中的内容应是:"135"。
注意: 部分源程序存在文件PROG1.C中。
请勿改动主函数main和其它函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
给定源程序:
#include
#include
void fun(char *s, char t[])
{
}
main()
{
char s[100], t[100];
printf("/nPlease enter string S:"); scanf("%s", s);
fun(s, t);
printf("/nThe result is: %s/n", t);
NONO();
}
问答题
给定程序MODI1.C中函数fun的功能是:将十进制正整数m转换成k(2≤k≤9)进制数,并按高位到低位顺序输出。
例如,若输入8和2,则应输出1000(即十进制数8转换成二进制表示是1000)。
请改正fun函数中的错误,使它能得出正确的结果。
注意:不要改动main函数。不得增行或删行,也不得更改程序的结构!
#include<conio.h>
#include<stdio.h>
void fun(int m, int k)
{
int aa[20], i;
for(i=0; m; i++)
{
/**********found**********/
aa[i]=m/k;
m/=k;
}
for(; i; i--)
/**********found**********/
printf("%d", aa[i]);
}
main()
{
int b, n;
printf("/nPlease enter a number and a base:/n");
scanf("%d %d",
fun(n, b);
printf("/n");
}
问答题请编写一个函数fun(),它的功能是:比较两个字符串的长度,(不得调用C语言提供的求字符串长度的函数),函数返回较短的字符串。若两个字符串长度相等,则返回第1个字符串。 例如,输入nanjing<CR>nanchang<CR>(<CR>为回车键),函数将返回nanjing。 注意:部分源程序给出如下。 请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。 试题程序: #include<stdio.h> char *fun(char *s,char *t) main() char a[20],b[10],*p,*q; int i; printf("Input lth string:"); gets(a); printf("Input 2th string:"); gets(b); printf("%s",fun(a,b));
问答题给定程序MODI1.C中函数fun的功能是: 交换主函数中两个变量的值。例如:
若变量a中的值原为8,b中的值为3。程序运行后a中的值为3, b中的值为8。
请改正程序中的错误, 使它能计算出正确的结果。
注意: 不要改动 main 函数, 不得增行或删行, 也不得更改程序的结构!
给定源程序:
#include
/*********found**********/
int fun(int x,int y)
{
int t;
/*********found**********/
t=x;x=y;y=t;
}
main()
{
int a,b;
a=8;b=3;
fun(
printf("%d, %d/n",a,b);
}
问答题给定程序中,函数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; 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]={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,其功能是分别统计形参t所指二维数组中字母A和c的个数。注意:部分源程序存在PROGl.C中,请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所缩写的若干语句。试题程序:
问答题请编写函数proc(),其功能是:将str所指字符串中下标为偶数的字符删除,串中剩余字符形成的新串放在t所指数组中。
例如,当str所指字符串中的内容为abcdefg,则在t所指数组中的内容应是bdf。
注意:部分源程序给出如下。
请勿改动main()函数和其他函数中的任何内容,仅在函数proc()的花括号中填入所编写的若干语句。
试题程序:
#include<stdlib.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
void proc(char*str, char t[])
{
}
void main()
{
char str[100], t[100];
system("CLS");
printf("/nPlease enter string str: ");
scanf("%s", str);
proc(str, t);
printf("/nThe result is: %s/n", t);
}
