全部知识点

第6681题

编写一个函数fun,从num个字符串中找出最长的一个字符串,并通过形参指针max传回该串地址。(注意:主函数中用****作为结束输入的标志。)

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void fun(char(*a)[81], int num, char **max)
{
int i, maxlen; 
maxlen=strlen(a[0]); 
for(①)
{
if(②)
{
③
*max=a[i];④
}
}
main()
{
	char ss[10][81], *ps;
	void NONO();
	int n, i=0;
	printf("输入若干个字符串:");
	gets(ss[i]);
	puts(ss[i]);
	while(!strcmp(ss[i],"****")==0)
	{
		i++;
		gets(ss[i]);
		puts(ss[i]);
	}
	n=i;
	fun(ss, n, &ps);
	printf("\nmax=%s\n", ps);
	NONO();
}
void NONO ()
{/* 请在此函数内打开文件,输入测试数据,
 调用函数,输出数据,关闭文件。 */
	char ss[20][81], *ps;
	int n, i=0;
	FILE *rf, *wf;
	rf=fopen("in.dat","r");
	wf=fopen("out.dat","w");
	fgets(ss[i], 81, rf);
	while(!strncmp(ss[i],"****",4)==0)
	{
		i++;
		fgets(ss[i], 81, rf);
	}
	n=i;
	fun(ss, n, &ps);
	fprintf(wf, "%s", ps);
	fclose(rf);
	fclose(wf);
	system("pause");
}


第6682题

给定程序中,函数fun的功能是:判定形参a所指的NxN(规定N为奇数)的矩阵是否是"幻方",若是,函数返回值为1;不是,函数返回值为0。“幻方"的判定条件是:矩阵每行、每列、主对角线及反对角线上元素之和都相等。

例如,以下3x3的矩阵就是一个"幻方":

4 9 2

3 5 7

8 1 6

不得增行或删行,也不得更改程序的结构!

#include <stdio.h>
#include <stdlib.h>
#define N 3
int fun(int (*a)[N])
{
	int i,j,m1,m2,row,colum;
	m1=m2=0;
	for(i=0; i<N; i++)
	{
		j=N-i-1; 
		m1+=a[i][i]; 
		m2+=a[i][j];
	}
	if(m1!=m2)
	{
		return 0;
	}
	for(i=0; i<N; i++) 
	{
		/**********found**********/
		row=colum=__(1)__;
		for(j=0; j<N; j++)
		{
			row+=a[i][j]; 
			colum+=a[j][i];
		}
		/**********found**********/
		if((row!=colum) __(2)__ (row!=m1))
		{
			return 0;
		}
	}
	/**********found**********/
	return __(3)__;
}
main()
{
	int x[N][N], i, j;
	printf("输入一个3×3的矩阵:\n");
	for(i=0; i<N; i++)
	{
		for(j=0; j<N; j++) 
		{
			scanf("%d", &x[i][j]);
		}
	}
	if(fun(x)) 
	{
		printf("这个矩阵是幻方\n");
	}
	else
	{
		printf("这个矩阵不是幻方\n");
	}
	system("pause");
}


第6683题

给定程序fun函数的功能是:根据整型形参m,计算如下公式的值:

Snipaste_2021-04-22_00-56-28.png

例如,若主函数中输入5,则应输出-0.283333

请改正程序中的错误,使它能得出正确的结果。

不要改动main函数,不得增行或删行,也不得更改程序的结构!

#include <stdio.h>
#include <stdlib.h>
double fun(int m)
{
	double t=1.0;
	int i;
	for(i=2; i<=m; i++)
	{
		/**********found**********/
		t = 1.0-1/i;
	}
	/**********found**********/
	______;
}
main()
{
	int m ;
	printf("\nPlease enter 1 integer numbers:\n");
	scanf("%d", &m);
	printf("\n\nThe result is %lf\n", fun(m));
	system("pause");
}


第6684题

请编写一个函数fun,函数的功能是删除字符串中的所有空格。

例如,主函数中输入"asd af aa 267",则输出为"asdafaaz67"

请勿改动主函数main和其它函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
void fun(char *str)
{
    int i=0;
    char *p=str;
    while(①)
    {
      if(②)
      {
        ③
      }
      ④
    }
    ⑤
}
main()
{
	char str[81];
	void NONO ();
	printf("Input a string:");
	gets(str);
	puts(str);
	fun(str);
	printf("*** str:%s\n",str);
	NONO();
}
void NONO ()
{/* 请在此函数内打开文件,输入调试数据,
 调用 fun 函数,输出数据,关闭文件。 */
	char str[81];
	int n=0;
	FILE *rf, *wf;
	rf=fopen("in.dat","r");
	wf=fopen("out.dat","w");
	while(n<8) 
	{
		fgets(str, 80, rf);
		fun(str);
		fprintf(wf, "%s", str);
		n++;
	}
	fclose(rf);
	fclose(wf);
	system("pause");
}


第6685题

给定程序中,函数fun的功能是根据形参i的值返回某个函数的值。当调用正确时,程序输出:

x1=5.000000,x2=3.000000,x1*x1 +x1*x2=40.000000

不得增行或删行,也不得更改程序的结构!

#include <stdio.h>
#include <stdlib.h>
double f1(double x)
{
	return x*x;
}
double f2(double x, double y)
{
	return x*y;
}
/**********found**********/
__(1)__ fun(int i, double x, double y)
{
	if(i==1)	
	{
		/**********found**********/
		return __(2)__(x);
	}
	else 
	{
		/**********found**********/
		return __(3)__(x,y);
	}
}
main()
{
	double x1=5, x2=3, r;
	r = fun(1, x1, x2);
	r += fun(2, x1, x2);
	printf("\nx1=%f, x2=%f, x1*x1+x1*x2=%f\n",x1, x2, r);
	system("pause");
}


第6686题

给定程序函数fun的功能是:比较两个字符串,将长的那个字符串的首地址作为函数值返回。

请改正程序中的错误,使它能得出正确的结果。

不要改动main函数,不得增行或删行,也不得更改程序的结构!

#include <conio.h>
#include <stdio.h>
/**********found**********/
char fun(char *s, char *t)
{
	int s1=0, t1=0;
	char *ss, *tt;
	ss=s;
	tt=t;	
	while(*ss)
	{
		s1++;
		/**********found**********/
		(*ss)++;
	}
	while(*tt)
	{
		t1++;
		tt++;
	}
	if (t1>s1)
	{
		return t;
	}
	else 
	{
		return s;
	}
}
main()
{
	char a[80],b[80];
	printf("\nEnter a string:");
	gets(a);
	printf("\nEnter a string again:");
	gets(b);
	printf("\n\nThe longer is:\n\n%s\n",fun(a,b));
	system("pause");
}


第6687题

请编写函数fun,函数的功能是:判断字符串是否为回文?若是,函数返回1,主函数中输出:YES;否则返回0,主函数中输出NO,回文是指顺读和倒读都一样的字符串。

例如,字符串LEVEL是回文,而字符串123312就不是回文。

请勿改动主函数main和其它函数中的任何内容,仅在函数fun中填入你编写的若干语句。

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define N 80
int fun(char *str)
{
    int i,n=0,fg=1;
    char *p=str;
    while(①)
    {
         ②
         ③
    }
    for(i=0;i<n/2;i++)
    {
         if(④)
        {
            ⑤
            ⑥
        }
    
    }
    return fg;

}
main()
{
char s[N];
void NONO();
printf("Enter a string:"); 
gets(s);
printf("\n");
puts(s);
if(fun(s)) 
{
printf("YES\n");
}
else 
{
printf("NO\n");
}
NONO();
system("pause");
}
void NONO()
{/* 请在此函数内打开文件,输入测试数据,
 调用函数,输出数据,关闭文件。 */
FILE *rf, *wf;
int i; 
char s[N];
rf=fopen("in.dat","r");
wf=fopen("out.dat","w");
for(i=0; i<8; i++)
{
fscanf(rf, "%s", s);
if(fun(s)) 
{
fprintf(wf, "%s YES\n", s);
}
else 
{
fprintf(wf, "%s NO\n", s);
}
}
fclose(rf); 
fclose(wf);
}
第6688题

用筛选法可得到2-n(n<10000)之间的所有素数,方法是:首先从素数2开始,将所有2的倍数的数从数表中删去(把数表中相应位置的值置成0);接着从数表中找下一个非0数,并从数表中删去该数的所有倍数;依此类推,直到所找的下一个数等于n为止。这样会得到一个序列:

2,3,5,7,11,13,17,19,23,....

函数fun用筛选法找出所有小于等于n的素数,并统计素数的个数作为函数值返回。

请在程序的下划线处填入正确的内容,使程序得出正确的结果。

不得增行或删行,也不得更改程序的结构!

#include <stdio.h>
#include <stdlib.h>
int fun(int n)
{
	int a[10000], i, j, count=0;
	for (i=2; i<=n; i++)
	{
		a[i] = i;
	}
	i = 2;
	while (i<n)
	{
		/**********found**********/
		for (j=a[i]*2; j<=n; j+=__(1)__)
		{
			a[j] = 0;
		}
		i++;
		/**********found**********/
		while (__(2)__==0)
		{
			i++;
		}
	}
	printf("\n 2 到 %d 的素数有:\n", n);
	for (i=2; i<=n; i++)
	{
		/**********found**********/
		if (a[i]!=__(3)__)
		{
			count++; 
			printf(count%15?"%5d":"\n%5d",a[i]);
		}
	}
	return count;
}
main()
{
	int n=30, r;
	r = fun(n);
	printf("\n素数的个数为:%d\n", r);
	system("pause");
}


第6689题

函数fun的功能是:为一个偶数寻找两个素数,这两个素数之和等于该偶数,并将这两个素数通过形参指针传回主函数。

请改正程序中的错误,使它能得出正确的结果。

不要改动main函数,不得增行或删行,也不得更改程序的结构!

#include <stdio.h>
#include <math.h>
void fun(int a,int *b,int *c)
{
	int i, j, d, y;
	for(i=3; i<=a/2; i=i+2)
	{
		/**************found**************/
		Y=1;
		for(j=2; j<=sqrt((double)i); j++)
		{
			if(i%j==0) 
			{
				y=0;
			}
		}
		if(y==1)
		{
			/**************found**************/
			d==a-i;
			for(j=2; j<=sqrt((double)d); j++)
			{
				if(d%j==0) y=0;
			}
			if(y==1)
			{ 
				*b=i; *c=d;
			}
		}
	}
}
main()
{
	int a,b,c;
	do
	{
		printf("\nInput a:"); 
		scanf("%d",&a);
	}
	while(a%2);
	fun(a,&b,&c);
	printf("\n\n%d = %d + %d\n",a,b,c);
	system("pause");
}


第6690题

请编写函数fun,它的功能是:计算并输出n(包括n)以内能被5或9整除的所有自然数的倒数之和。

例如,在主函数中从键盘给n输入20后,输出为:s=0.583333.

请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。

#include <stdio.h>
#include <stdlib.h>
double fun(int n)
{
    int i;
    double sun=0.0;
    for(i=1;i<n;i++)
    {
        if(①)
        {
             ②
        }
    }
    return sum;
}
main()
{
	void NONO();
	int n; 
	double s;
	printf("\nInput n: "); 
	scanf("%d",&n);
	s=fun(n);
	printf("\ns=%f\n",s);
	NONO();
	system("pause");
}
void NONO()
{/* 请在此函数内打开文件,输入测试数据,
 调用函数,输出数据,关闭文件。 */
	FILE *rf, *wf; 
	int n, i; 
	double s;
	rf=fopen("in.dat","r");
	wf=fopen("out.dat","w");
	for(i=0; i<8; i++) 
	{
		fscanf(rf, "%d", &n);
		s=fun(n);
		fprintf(wf, "%lf\n", s);
	}
	fclose(rf); 
	fclose(wf);
}


第6691题

函数fun的功能是:从三个形参a,b,c中找出中间的那个数,作为函数值返

回。例如,当a=3, b=5, c=4时,中数为4。

请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。

注意:不得增行或删行,也不得更改程序的结构!

int fun(int a, int b, int c)
{
    int t; t = (a>b) ? (b>c? b :(a>c?c:___1___)) : ((a>c)?___2___ : ((b>c)?c:___3___)); 
    return t;
}
第6692题

给定程序中函数fun的功能是:首先将大写字母转换为对应小写字母;若小写字母为a~u,则将其转换为其后的第5个字母;若小写字母为v~z,使其值减21,转换后的小写字母作为函数值返回例如,若形参是字母A,则转换为小写字母;若形参是字母W,则转换为小写字母b。

请改正程序中的错误,使它能得出正确的结果。

不要改动main函数,不得增行或删行,也不得更改程序的结构!

#include<stdio.h>
#include<stype.h>
char fun(char c)
{
    /********found********/
    if (c>= 'A' && c<='Z')
        c = c-32;
/********found********/
    if (c>='a' && c<='u')
        c = c-5;
    else if (c>='v' && c<='z')
        c = c-21;
    return c;
}
main ( )
{
    char cl, c2;
    printf("\nEnter a letter(A-Z):");
    cl = get char( );
    if (isupper(cl))
    {
        c2 = fun(cl);
        printf("\n k nThe letter %c change to %c\n",cl,c2);
    }
    else
    {
        printf("\nEnter (A-Z) !\n");
    }
}
第6693题

请编写函数fun,其功能是:计算并输出:s=1+(1+根号2)+(1+根号2+根号3)+....+(1+根号12+根号3+...+根号n)(要求n的值大于1但不大于100)

例如,在主函数中从键盘给n输入20后,输出为:s=534.188884

请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。

#include <math.h>
#include <stdio.h> 
double fun(int n)
{

}
main ()
{
	 int n; double s;
	printf("\n\nlnput n: "); 
	scanf("%d",&n);
	s=fun(n);
	printf("\n\ns=%f\n\n",s);
	NONO();
)
NONO ()
{/*请在此函数内打开文件,输入测试数据, 调用fun函数,输出数据,关闭文件.*/
	FILE *rf, *wf; int n, i; double s;
	rf = fopen("in.dat", "r");
	wf - fopen("out.dat",“w”);
	for(i = 0 ; i < 10 ; i++) 
	{
		fscanf(rf, "%d", &n);
		s = fun(n);
		fprintf(wf, ”%lf\n", s);
		fclose(rf); 
		fclose(wf);
	}
}


第6694题

给定程序中已建立一个带有头结点的单向链表,在main函数中将多次调用fun函数,每调用一次fun函数,输出链表尾部结点中的数据,并释放该结点,使链表缩短。

请在程序的下划线处填入正确的内容,使程序得出正确的结果。

不得增行或删行,也不得更改程序的结构!

#include <stdio.h>
#include <stdlib.h>
#define N 8
typedef struct list
{
	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);
	}
	system("pause");
}
第6695题

函数fun的功能是:将字符串中的字符按逆序输出,但不改变字符串中的内容。

例如,若字符串为abcd,则应输出:dcba,请改正程序中的错误,使它能得出正确的结果。

不要改动main函数,不得增行或删行,也不得更改程序的结构!

#include <stdio.h>
#include <stdlib.h>
/**********found**********/
fun (char a)
{
	if (*a)
	{
		fun(a+1);
		/**********found**********/
		printf("%c" *a);
	}
}
main()
{
	char s[10]="abcd";
	printf("处理前字符串:%s\n处理后字符串:", s);
	fun(s); 
	printf("\n");
	system("pause");
}
第6696题

请编写函数fun,其功能是:将所有大于1小于整数m的非素数存入xx所指数组中,非素数的个数通过k传回。

例如,若输入:17,则应输出:46891012141516

请勿改动主函数main和其它函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。

#include <stdio.h>
#include <stdlib.h>
void fun(int m, int *k, int xx[])
{
     int i,j, n=0;
     for(i=2;i<m;i++)/*找出大于1小于整数m的非素数*/
     {
     for(j=2;j<i;j++)     } 
}
main()
{
	int m, n, zz[100];
	void NONO ();
	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]);
	}
	NONO();
	system("pause");
}
void NONO()
{/* 请在此函数内打开文件,输入测试数据,
 调用函数,输出数据,关闭文件。 */
	int m, n, zz[100];
	FILE *rf, *wf;
	rf=fopen("in.dat","r");
	wf=fopen("out.dat","w");
	fscanf(rf, "%d", &n);
	fun(n, &m, zz);
	fprintf(wf, "%d\n%d\n", m, n);
	for(n=0; n<m; n++)
	{
		fprintf(wf, "%d\n", zz[n]);
	}
	fclose(rf);
	fclose(wf);
}
第6697题

请补充函数proc,其功能是:计算下面公式S的值:

Snipaste_2021-04-30_09-41-32.png


例如,当N=20时,SN=29.031674

注意:请勿改动main函数和其他函数中的任何内容,仅在函数proc的横线上填入所编写的若干表达式或语句。

#include <stdio.h>
#include <stdlib.h>
double proc(int n)
{
	double s=1.0, sl=0.0;
	int k;
	/**********found**********/
	for(__(1)__; k<=n; k++)
	{
		sl=s;
		/**********found**********/
		__(2)__;
	}
	/**********found**********/
	return __(3)__;
}
void main()
{
	int k=0;
	double sum;
	system("CLS");
	printf("\nPlease input N=");
	scanf("%d", &k);
	sum=proc(k);
	printf("\nSN=%lf", sum);
	system("pause");
}


第6698题

函数proc的功能是:根据整型形参n,计算如下公式的值:

Snipaste_2021-04-30_09-43-05.png


例如,n中的值为10,则应输出0.817962,请改正程序中的错误,使它能得出正确的结果。

不要改动main函数,不得增行或删行,也不得更改程序的结构!

#include <stdio.h>
#include <stdlib.h>
double proc(int n)
{
	double y=1.0;
	/**********found**********/
	int j=1;
	int i;
	for(i=2; i<=n; i++)
	{
		j=-1*j;
		/**********found**********/
		y+=1/(i*i);
	}
	return(y);
}
void main()
{
	int n=10;
	system("CLS");
	printf("\nThe result is %lf\n", proc(n));
	system("pause");
}


第6699题

编写一个函数proc,从传入的M个字符中找出最长的一个字符串,并通过形参指针max传回该串地址(用***作为结束输入的标志)。

请勿改动main0函数和其他函数中的任何内容,仅在函数proc的花括号中填入所编写的若干语句。

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void proc(char(*a)[81],int num,char **max)
{
	int i;
	*max=a[0];
	for(①)
	{
	    if(②)
	    {
	        ③
	    }
	}
}
main()
{
	void NONO();
	char ss[10][81],*ps;
	int n,i=0;
	printf("输入若干个字符串:");
	gets(ss[i]);
	puts(ss[i]);
	while(!strcmp(ss[i],"****")==0)
	{
		i++;
		gets(ss[i]);
		puts(ss[i]);
	}
	n=i;
	proc(ss,n,&ps);
	printf("\nmax=%s\n",ps);
	NONO();
	system("pause");
}
void NONO()
{/* 请在此函数内打开文件,输入测试数据,
 调用 函数,输出数据,关闭文件。 */
	char ss[20][81],*max;
	int n,i=0;
	FILE *rf, *wf;
	rf=fopen("in.dat","r");
	wf=fopen("out.dat","w");
	fgets(ss[i], 81, rf);
	while(!strncmp(ss[i],"****",4)==0)
	{
		i++;
		fgets(ss[i], 81, rf);
	}
	n=i;
	proc(ss, n, &max);
	fprintf(wf, "%s",max);
	fclose(rf);
	fclose(wf);
}


第6700题

给定程序BLANK1.C中,函数fun的功能是在数组中找出两科成绩之和最高的学生并返回其在数组中的下标。对所给函数int fun(STU*d,int n),主函数传给形参d的是学生数组名,而传给形参n的是该数组中学生的个数。

例如,若学生数组数据为:

2016500301李清水83 92

2016500336 刘世才85 94

2016500371王子晨88 88

则调用该函数后,程序输出为:2016500336刘世才85 94

请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。

注意:不得增行或删行,也不得更改程序的结构!

#include<stdio.h>
typedef struct stu
{
	char ID[30];
	char name[20];
	int score[2];
} STU;
int fun(STU *d,int n)
{
	int i,m;
	/******found******/
	______(1)______;
	for(i=1;i<n;i++)
	/******found******/
		if(d[i].score[0]+d[i].score[1]>________(2)________)
			m=i;
	/******found******/
	______(3)______;
}

void main()
{
	STU a[10]={ "2016500301","李清水",83,92,"2016500336","刘世才",85,94,"2016500371","王子晨",88,88};
	int i,n=3;
	i=fun(a,n);
	printf("%30s%20s%4d%4d",a[i].ID,a[i].name,a[i].score[0],a[i].score[1]);
	printf("\n");
}