问答题int x=6, y=7;
printf(“%d,”,x++);
printf(“%d\n”,++y);
程序的输出结果是__________ 。
问答题用筛选法可得到2~n(n<10000)之间的所有素数,方法是:首先从素数2开始,将所有2的倍数的数从数表中删去(把数表中相应位置的值置成0);接着从数表中找下一个非0数,并从数表中删去该数的所有倍数;依此类推,直到所找的下一个数等于n为止。这样会得到一个序列: 2,3,5,7,11,13,17,19,23,…… 函数fun用筛选法找出所有小于等于n的素数,并统计素数的个数作为函数值返回。 请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。注意:源程序存放在考生文件夹下的BLANK1.C中。不得增行或删行,也不得更改程序的结构!1 #include<stdio.h>2 int fun(int n)3 { int a[10000],i,j,count=0;4 for(i:2;i<=n; i++)a[i]=i;5 i=2;6 while(i<n) {7 /**********found**********/8 for(j=a[i]*2;j<=n;j+=__1__)9 a[j]=0;10 i++;11 /**********found**********/12 while(__2__==0)13 i++;14 }15 printf(''\nThe prime number between 2 to %d\n'',n);16 for(i=2; i<=n;i++)17 /**********found**********/18 if(a[i]!=__3__ )19 {count++; printf(count%157''%5d'':''\n%5d'',a[i]);}20 return count;21 }22 main()23 { int n=20,r;24 r=fun(n);25 printf(''\nThe number of prime is:%d\n'',r);}
问答题编写函数fun,其功能是:将两个两位数的正整数a、b合并成—个整数放在c中。合并的方式是:将a数的十位和个位数依次放在c数的十位和千位上,b数的十位和个位数依次放在c数的百位和个位上。例如,当a=45,b:12时,调用该函数后,c=5142。注意:部分源程序给出如下。数据文件IN.DAT中的数据不得修改。请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入编写的若干语句。试题程序:#include<stdlib.h>#inclucle<stdio.h>#include<conio.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",&a,&b); fun(a,b,&c); printf("The result is:%ld\n”,c);}
问答题假定输入的字符串中只包含字母和*号。请编写函数 fun(),它的功能是:将字符串尾部的*号全部删除,前面和中间的*号不删除。 例如,若字符串中的内容为****A*BC*DEF*G*******删除后,字符串中的内容则应当是****A*BC*DEF*G。 注意:部分源程序给出如下。 请勿改动主函数main和其他函数中的任何内容,仅在函数6ln的花括号中填入所编写的若干语句。 试题程序: #include <stdio,h> #include <conio.h> void fun (char *a) main() char s[81]; printf("Enter a string :/n"); gets(s); fun(s); printf("The string after deleted:/n"); puts(s);
问答题给定程序MODll.C中函数fun的功能是:输出M行M列整数方阵,然后求两条对角线上元素之和,返回此和数。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!
#incllade
#define M 5
/**********found***********/
int fun(int n, int xx[][])
{ int i,j,sum=0;
printf(“\nThe%d X%d matrix:\n”,
M,M);
for(i=0;i
问答题给定程序中,函数fun的功能是:有N×N矩阵,以主对角线为对称线,对称元素相加并将结果存放在左下三角元素中,右上三角元素置为0。例如,若N=3,有下列矩阵:
1 2 3
4 5 6
7 8 9
计算结果为
1 0 0
6 5 0
10 14 9
请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。
注意:源程序存放在考生文件夹下的BLANK1.C中。不得增行或删行,也不得更改程序的结构!
给定源程序:
#include
#define N 4
/**********found**********/
void fun(int (*t)___1___ )
{ int i, j;
for(i=1; i
{ for(j=0; j
{
/**********found**********/
___2___ =t[i][j]+t[j][i];
/**********found**********/
___3___ =0;
}
}
}
main()
{ int t[][N]={21,12,13,24,25,16,47,38,29,11,32,54,42,21,33,10}, i, j;
printf("/nThe original array:/n");
for(i=0; i
{ for(j=0; jprintf("/n");
}
fun(t);
printf("/nThe result is:/n");
for(i=0; i
{ for(j=0; jprintf("/n");
}
}
问答题规定输入的字符串中只包含字母和*号。请编写函数fun,其功能是:使字符串的前导*号不得多于n个,若多于n个,则删除多余的*号;若少于或等于n个,则不做处理。字符串中间和尾部的*号不删除。
例如,字符串中的内容为“*******A*BC*DEF*G****”,若n的值为4,删除后,字符串中的内容应当是“****A*BC*DEF*G****”;若n的值为8,则字符串中的内容仍为“*******A*BC*DEF*G****”。n的值在主函数中输入。在编写函数时,不得使用C语言提供的字符串函数。
注意
:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
试题程序:
#include <stdio.h>
#include <conio.h>
void fun(char *a,int n)
{
}
void main()
{
char s[81];int n;
printf("Enter a string:/n");
gets(s);
printf("Enter n:");
scanf("%d",
fun(s,n);
printf("The string after deleted:/n");
puts(s);
}
问答题下列给定程序中,函数fun的功能是:从低位开始依次取出长整型变量s中奇数位上的数,构成一个新数存放在t中。高位仍在高位,低位仍在低位。例如,当s中的数为7654321时,t中的数为7531。请改正程序中的错误,使它能得出正确的结果。注意:部分源程序在文件MODll.C中,不得增行或删行,也不得更改程序的结构! #include<stdio.h> /**********found**********/ void fun(10ng s,long t) {long s1=10; ,it t=s%10: while(s>0) { s=s/100; *t=s%10*s1+*t: /**********found**********/ s1=s1*100: } } main() {long s,t; prinff(“\nPlease enter s:”);scanf(“%ld”,&s); fun(s,&t); prinff(“The result is:%1d\n”,t); }
问答题下列给定程序中,函数fun和funx的功能是:用二分法求方程2x
3
一4x
2
+3x一6=0的一个根,并要求绝对误差不超过0.001。
例如,若给m输入一100,给n输入90,则函数求得的一个根为2.000。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!
试题程序:
#include < stdio.h >
#include < math.h >
double funx(double x)
{
return(2*x*x*x一4*x*x+3*x一6);
}
double fun(double m,double n)
{
/*********found*********/
int r;
r=(m+n)/2;
/*********found*********/
while(1abs(n一m) < 0.001)
{
if(funx(r)jIc funx(n) < 0)
m=r;
else
n=r;
r=(m+n)/2;
}
return r;
}
main()
{
double m,n,root;
printf("Enter m n:/n");
scanf("%lf%lf",&m,&n);
root=fun(m,n);
printf("root=%6.3f/n",root);
}
问答题用程序计算下列表达式:s=1!+2!+3!+4!
问答题请编写函数fun,该函数的功能是:统计一行字符串中单词的个数,作为函数值返回。字符串在主函数中输入,规定所有单词由小写字母组成,单词之间有若干个空格隔开,一行的开始没有空格。注意:部分源程序在文件PROG1.C中。请勿改动main函数和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。试题程序:1 #include<string.h>2 #inclucte<stdio.h>3 #define N 804 int fun(char*s)5 {67 }8 void main()9 {10 FILE*wf;11 char line[N];12 int num=0;13 printf("Enter a string:\n");14 gets(line);15 num=fun(line);16 printf("The number of wordis:%d\n\n",num);17 /*********found*********/18 wf=fopen("out.clat","w");19 fprintf(wf,"%d",fun("a big car"));20 fclose(wf);21 /*********found*********/22 }
问答题
给定程序MODI1.C中函数fun的功能是:求出两个非零正整数的最大公约数,并作为函数值返回。
例如,若给num1和num2分别输入49和21,则输出的最大公约数为7;若给num1和num2分别输入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);
}
main()
{int num1, num2, a;
printf("Input num1 num2:");
scanf("%d%d",
printf("num1=%d num2=%d/n/n", num1, num2);
a=fun(num1, num2);
printf("The maximun common divisor is %d/n/n", a);
}
问答题规定输入的字符串中只包含字母和*号。请编写函数fun,其功能是:只删除字符前导和尾部的*号,串中字母间的*号都不删除。形参n给出了字符串的长度,形参h给出了字符串中前导*号的个数,形参e给出了字符串中尾部*号的个数。在编写函数时,不得使用C语言提供的字符串函数。
例如,字符串中的内容为“****A*BC*DEF*G*******”,删除后,字符串中的内容应当是“A*BC*DEF*G”。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
试题程序:
#include<stdio.h>
#include<conio.h>
void fun(char*a, int n, int h, int e)
{
}
void 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++; } /*m为字符串的长度*/
t--; /*指针t指向字符串尾部*/
while(*t=="*")
{t--; tn++; }
/*指针t指向最后一个字母, tn统计尾部"*"的个数*/
while(*f=="*")
{f++; fn++;}
/*指针f指向第一个字母, fn统计前导"*"的个数*/
fun(s, m, fn, tn);
printf("The string after deleted:/n");
puts(s);
}
问答题编写函数fun,其功能是:根据以下公式求值(要求精度0.0005,即某项小于0.0005时停止迭代)。程序运行后,若输入精度0.0005,则程序应输出为3.14…注意:部分源程序已给出。请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。试题程序:#include<stdio.h>#include<conio.h>#include<math.h>doublefun(doubleeps)voidmain()doublex;printf("Inputeps:");scanf("%If”,&x);printf("/neps=%If,PI=%1f/n",x,fun(x));
问答题函数fun的功能是:将s所指字符串中下标为偶数同时ASCII值为奇数的字符删除,s所指串中剩余的字符形成的新串放在t所指的数组中。
例如,若s所指字符串中的内容为"ABCDEFC12345",其中字符C的ASCII码值为奇数,在数组中的下标为偶数,因此必须删除;而字符1的ASCII码值为奇数,在数组中的下标为奇数,因此不应当删除,其他依此类推。最后t所指的数组中的内容应是"BDF12345"。
注意:请勿改动main函数和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
试题程序:
#include<stdio.h>
#include<string.h>
void fun(char*s,char t[])
{
}
main()
{
char s[100],t[100];void NONO();
printf("/nPlease enter string S:");
scanf("%s",s);
fun(s,t);
printf("/nThe result is:%s/n",t);
NONO();
}
void NONO()
{/*本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。*/
char s[100],t[100];
FILE*rf,*wf;
int i;
rf=fopen("in.dat","r");
wf=fopen("out.dat","w");
for(i=0;i<10;i++){
fscanf(rf,"%s",s);
fun(s,t);
fprintf(wf,"%s/n",t);
}
fclose(rf);
fclose(wf);
}
问答题给定程序中已建立一个带有头结点的单向链表,在main函数中将多次调用fun函数,每调用一次fun函数,输出链表尾部结点中的数据,并释放该结点,使链表缩短。请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。 注意:源程序存放在考生文件夹下的BLANK1.C中。 不得增行或删行,也不得更改程序的结构!#include<stdio.h>#include<stdlib.h>#define N 8 typedef struct 1ist{ int data; struct list *next;}SLIST;void fun(SLIST *p){SLIST *t,*s; t=p一>next;s=p; while(t->next !=NULL) { s=t;/**********found**********/ t=t-> 【1】 ; } /**********found**********/ printf("%d",【2】); s一>next=NULL; /**********found**********/ free(【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一>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]={11,12,15,18,19,22,25, 29}; head=creatlist(a);printf("\nOutput from head:\n");outlist(head);printf("\nOutput from tail:\n"); while (head一>next !=NULL){ fun(head); printf("\n\n"); printf("\nOutput from head again:\n");outlist(head); } }
问答题下列程序定义了NXN的二维数组,并在主函数中赋值。请编写函数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 <stdio.h>
#include<conio.h>
#include<stdlib.h>
#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<N;i++)
{ for(j=0;j<N;i++)
{printf("%4d",a[i][j]);}
printf("/n");
}
s=fun(a);
printf("*****THE RESULT*****/n");
printf("The sum is:%d/n",s);
}
问答题给定程序中,函数fun的功能是:计算形参x所指数组中N个数的平均值(规定所有数均为正数),将所指数组中大干平均值的数据移至数组的前部,小于等于平均值的数据移至x所指数组的后部,平均值作为函数值返回,在主函数中输出平均值和移动后的数据。例如,有10个正数:46、30、32、40、6、17、45、15、48、26,平均值为30.500000。移动后的输出为:46、32、40、45、48、30、6、17、15、26。请在程序的下画线处填入正确的内容并把下画线删除,使程序得出正确的结果。注意:部分源程序在文件BLANK1.C中。不得增行或删行,也不得更改程序的结构!试题程序:
问答题给定程序MODI1.C中函数fun的功能是:将s所指字符串中出现的与t1所指字符串相同的子串全部替换成t2所指字符串,所形成的新串放在w所指的数组中。在此处,要求t1和t2所指字符串的长度相同。
例如,当s所指字符串中的内容为:"abcdabfab",t1所指子串中的内容为:
"ab",t2所指子串中的内容为:"99"时, 结果在w所指的数组中的内容应为:
"99cd99f99"。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!
给定源程序:
#include
#include
int fun (char *s, char *t1, char *t2 , char *w)
{
int i; char *p , *r, *a;
strcpy( w, s );
while ( *w )
{ p = w; r = t1;
/************found************/
while ( r )
if ( *r == *p ) { r++; p++; }
else break;
if ( *r == '/0' )
{ a = w; r = t2;
while ( *r ){
/************found************/
*a = *r; a++; r++
}
w += strlen(t2) ;
}
else w++;
}
}
main()
{
char s[100], t1[100], t2[100], w[100];
printf("/nPlease enter string S:"); scanf("%s", s);
printf("/nPlease enter substring t1:"); scanf("%s", t1);
printf("/nPlease enter substring t2:"); scanf("%s", t2);
if ( strlen(t1)==strlen(t2) ) {
fun( s, t1, t2, w);
printf("/nThe result is : %s/n", w);
}
else printf("Error : strlen(t1) != strlen(t2)/n");
}
问答题在主函数中已将N名学生的成绩放入一个带头结点的链表结构中,h指向链表的头结点。请编写函数fun,它的功能是:求出平均分,由函数值返回。 例如,若学生的成绩是:85,76,69,85,91,72,64,87,则平均分应当是:78.625。 注意:部分源程序在文件PROG1.C中。 请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。 文件PROG1.C内容如下: #include<stdio.h> #include<stdlib.h> #define N 8 struct slist double s ; struct stist * next; ; typedef struct slist STREC; double fun(STREC * h ) STREC * creat( double * s) STREC * h, * p, * q; int i=0; h = p = (STREC * ) malloe (sizeof( STREC )); p->s=0; while(i<N) q=(STREC * ) malloe ( sizeof( STREC ) ) ; q->s=s[i] ; i++; p->next = q ; p=q; p->next = 0 ; return h ; void outlist (STREC * h) STREC * p ; p = h->next ; prinff( " head" ) ; do prinff( " ->% 4.1f" , p->s) ; p=p->next; while(p! =0); printf(" /n/n" ) ; void main( ) double s[N]=85,76,69,85,91,72,64,87,ave; STREC * h ; h=creat( s ); outlist (h) ; ave=fun( h ); prinff("ave= %6.3f/n" ,ave) ;
