问答题函数fun()的功能是:从s所指字符串中,找出与t所指字符串相同的子串的个数作为函数值返回。例如,当s所指字符串中的内容为”abcdabfab”,t所指字符串的内容为”ab”,则函数返回整数3。 请改正程序中的错误,使它能得出正确的结果。 #include <stdio.h> #include <string.h> int fun(char *s,char *t) int n;char *p,*r; n=0; while(*s) p=s;r=t; while(*r) if(*r==*p) /**********found**********/ r++;p++ else break; /**********found**********/ if(r=='/0') n++; s++; return n; main() char s[100],t[100];int m; printf("/nPlease enter string S:");scanf("%s",s); printf("/nPlease enter substring t:");scanf("%s",t); m=fun(s,t); printf("/nThe result is:m=%d/n",m);
问答题给定程序中,函数fun的功能是将带头节点的单向链表结点数据域中的数据从小到大排序。即若原链表结点数据域从头至尾的数据为:10、4、2、8、6,排序后链表结点数据域从头至尾的数据为:2、4、6、8、10。
请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。
注意:源程序存放在
下的BLANK1.C中。
不得增行或删行,也不得更改程序的结构!
#include<stdio.h>
#include<stdlib.h>
#define N 6
typedef struct node {
int data;
struct node *next;
} NODE;
void fun(NODE *h)
{NODE *p, *q; int t;
/**********found**********/
p=______;
while(p){
/**********found**********/
q=______;
while(q){
/**********found**********/
if(p->data______q->data)
{t=p->data; p->data=q->data; q->data=t;}
q=q->next;
}
p=p->next;
}
}
NODE*creatlist(int a[])
{NODE *h, *p, *q; int i;
h=(NODE*)malloc(sizeof(NODE));
h->next=NULL;
for(i=0; i<N; 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]={0,10,4,2,8,6};
head=creatlist(a);
printf("/nThe original list:/n");
outlist(head);
fun(head);
printf("/nThe list after sorting:/n");
outlist(head);
}
问答题下列给定程序中,函数fun的功能是:计算整数n的阶乘。请改正程序中的错误,使它能得出正确的结果。注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!试题程序:#include<stdlib.h>#include<stdio.h>double fun(int n){ double result:1.0; while(n>1&&n<170)/******found******/ result*c=一一n:/******found******/ return;}void main(){ int n; prinff(“Enter fill integer:”); seanf(“%d”,&n); printf(“\n%d!=%1g\n”,n,fun(n));}
问答题给定程序中,函数fun的功能是:计算下式前n项的和,并作为函数值返回。例如,当形参n的值为10时,函数返回一0.204491。请在程序的下画线处填入正确的内容并把下画线删除,使程序得出正确的结果。注意:源程序给出如下。不得增行或删行,也不得更改程序的结构!试题程序:#inclucle<stdio.h>doublefun(intn){inti,k;doubles,t;s=0;/*********found*********/k=【1】;for(i=1;i<=n;i++){/*********found*********/t=【2】;s=s+k*(2*i一1)*(2*i+1)/(t*t);/*********found*********/k=k*【3】;}returns;}main(){intn=-1;while(n<0){printf("Pleaseinput(n>0):");scanf("%d',&n);}printf("\nTheresultis:%f\n",fun(n));}
问答题给定程序MODI1.C中函数 fun 的功能是:求出以下分数序列的前n项之和。和值通过函数值返回到main函数。
2 3 5 8 13 21
┄┄ , ┄┄ , ┄┄ , ┄┄ , ┄┄ , ┄┄ , ……
1 2 3 5 8 13
例如,若n = 5,则应输出:8.391667。
请改正程序中的错误,使它能计算出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!
给定源程序:
#include
/************found************/
fun ( int n )
{ int a, b, c, k; double s;
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;
}
return s;
}
main( )
{ int n = 5;
printf( "/nThe value of function is: %lf/n", fun ( n ) );
}
问答题下列给定程序中函数fun()的功能是:将p所指字符串中的所有字符复制到b中,要求每复制3个字符之后插入一个空格。
例如,若给a输入字符串:ABCDEFGHIJK,调用函数后,字符数组b中的内容为:ABC DEF GHI
JK。请改正程序中的错误,使它能得出正确结果。
注意:不要改动main()函数,不得增行或删行,也不得更改程序的结构。
试题程序 #include
<stdio.h> void fun(char *p, char *b) { int i,
k=0; while(*p) { i=1; while(i<=3 k++; p++; i++; }
if(*p) { /* * * * *found* * * * * / b[k++]="
"; } } b[k]='/0';
} main() { char a[80], b[80];
printf("Enter a string:"); gets(a);
printf("The original string:"); puts(a); fun(a, b);
printf("/nThe string after insert space:"); puts(b);
printf("/n/n"); }
问答题函数fun的功能是:逆置数组元素中的值。例如:若a所指数组中的数据依次为:1、2、3、4、5、6、7、8、9,则逆置后依次为:9、8、7、6、5、4、3、2、1。形参n给出数组中数据的个数。
请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。
注意:源程序存放在考生文件夹下的BLANK1.C中。
不得增行或删行,也不得更改程序的结构!
#include
void fun(int a[], int n)
{ int i,t;
/********** found********** /
for (i=0; i<【1】; i++)
{
t=a[i];
/ ********** found********** /
a[i] = a[n-l-【2】];
/ ********** found********** /
【3】 = t;
}
}
main ()
{ int b[9] ={1,2,3,4,5,6,7,8,9},i;
printf("/nThe original data:/n");
for (i=0; i<9; i++)
printf("%4d ", b[i]);
printf("/n");
fun(b, 9);
printf("/nThe data after invert:
/n");
for (i=0; i<9; i++)
printf("%4d ", b[i]);
printf("/n") ;
}
问答题给定程序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}
问答题请编写函数proc(),该函数的功能是:将M行N列的二维数组中的数据,按行的顺序依次放到一维数组中,一维数组中数据的个数存放在形参n所指的存储单元中。
例如,若二维数组中的数据为:
13 23 33 43
14 24 34 44
15 25 35 45
则一维数组中的内容应该是13 23 33 43 14 24 34 44 15 25 35 45。
注意:部分源程序给出如下。
请勿改动main()函数和其他函数中的任何内容,仅在函数proc()的花括号中填入所编写的若干语句。
试题程序:
#include<stdio.h>
void proc(int(*s)[10],int*b,int*n,int mm,int nn)
{
void main()
{
int arr[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",arr[i][j]);
printf("/n");
}
proc(arr,a,
printf("The a array:/n");
for(i=0;i<n;i++)
printf("%3d",a[i]);
printf("/n/n");
}
问答题请编写函数fun,它的功能是求出能整除形参x且不是偶数的各整数,并按从小到大的顺序放在pp所指的数组中,这些除数的个数通过形参n返回。
例如,若x中的值为:35,则有4个数符合要求,它们是:1,5,7,35。
注意:部分源程序存在文件PROG1.C中。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入编写的若干语句。
给定源程序如下。
#include<stdio.h>
void fun(int x,int pp[],int*n)
{
}
main()
{int x,aa[1000],n,i;
printf("/nPlease enter an integer number:/n");
scanf("%d",
fun(x,aa,
for(i=0;i<n;i++)
printf("%d",aa[i]);
printf("/n");
}
问答题学生的记录由学号和成绩组成,N名学生的数据已在主函数中放入结构体数组s中,请编写函数fun,它的功能是:把分数最低的学生数据放在b所指的数组中,注意:分数最低的学生可能不止一个,函数返回分数最低的学生的人数。
注意:部分源程序在文件PROG1. C文件中。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
#include <stdio. h>
#define N 16
typedef struct
{ char num[10];
int s;
}STREC;
int fun(STREC *a, STREC *b)
{
}
main( )
{STREC s[N]={{"GA05", 85), {"GA03", 76},
{"GA02", 69}, {"GA04", 85), {"GA01", 91},
{"GA07", 72}, {"GA08", 64}, {"GA06", 87},
{"GA015", 85}, {"GA013", 91}, {"GA012", 64},
{"GA014", 91}, {"GA011", 91}, {"GA017", 64},
{"GA018", 64), {"GA016", 72}};
STREC h[N];
int i, n; FILE *out;
n=fun(s, h);
printf("The %d lowest score:/n", n);
for(i=0; i<n; i++)
printf("%s %4d/n", h[i]. num, h[i]. s);
printf("/n");
out=fopen("out. dat", "w");
fprintf(out, "%d/n", n);
for(i=0; i<n; i++)
fprintf(out, "%4d/n", h[i]. s);
fclose(out);
}
问答题请编写函数fun,函数的功能是:将大于形参m且紧靠m的k个素数存入xx所指的数组中。函数prime判断一个数是否为素数,是返回1,否则返回0。例如,若输入17,5,则应输出:19,23,29,31,37。函数fun中给出的语句仅供参考。
请勿改动主函数main和其它函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
给定源程序:
#include<stdio.h>
int prime(int n)
{
int m;
for(m=2; m<n; m++)
if(n%m==0)
return 0;
return 1;
}
void fun(int m, int k, int xx[])
{
/*以下代码仅供参考*/
int j=0, t=m+1;
while(j<k)
{
/*按题目要求完成以下代码*/
}
}
main()
{
int m, n, zz[1000];
printf("/Please enter two integers:");
scanf("%d%d",
fun(m, n, zz);
for(m=0; m<n; m++)
fprintf("%d", zz[m]);
printf("/n");
}
问答题函数fun的功能是:将a、b中的两个两位正整数合并形成一个新的整数放在c中。合并的方式是:将a中的十位和个位数依次放在变量c的百位和个位上,b中的十位和个位数依次放在变量c的十位和千位上。
例如,当a=45,b=12。调用该函数后,c=2415。
请勿改动主函数main和其它函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
给定源程序:
#include<stdio.h>
void fun(int a,int b,long*c)
{
}
main()
{int a,b;long c;
printf("Input a b:");
scanf("%d%d",
fun(a,b,
printf("The result is:%ld/n",c);
}
问答题规定输入的字符串中只包含字母和*号。请编写函数fun,其功能是:将字符串尾部的*号全部删除,前面和中间的*号不动。
例如,字符串中的内容为:“****A*BC*DEF*G*******”,删除后,字符串中的内容应当是:“****A*BC*DEF*G”。在编写函数时,不得使用C语言提供的字符串函数。
注意:请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
#include<stdio.h>
void fun(char*a)
{
}
main()
{char s[81];void NONO();
printf("Enter a string:/n");gets(s);
fun(s);
printf("The string after deleted:/n");puts(s);
NONO();
}
void NONO()
{/*本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。*/
FILE*in,*out;
int i;char s[81];
in=fopen("in.dat","r");
out=fopen("out.dat","w");
for(i=0;i<10;i++)
{
fscanf(in,"%s",s);
fun(s);
fprintf(out,"%s/n",s);
}
fclose(in);
fclose(out);
}
问答题给定程序MODI1.C中函数fun的功能是:从低位开始取出长整型变量s中奇数位上的数,依次构成一个新数放在t中。高位仍在高位,低位仍在低位。
例如,当s中的数为7654321时,t中的数为7531。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
#include<stdio-h>
/**********found**********/
void fun(long s,long t)
{long s1=10;
*t=s%10;
while(s>0)
{s=s/100;
*t=s%10*s1+*t;
/**********found**********/
s1=s1*100;
}
}
main()
{long s,t;
printf("/nPlease enter s:");scanf("%1d",
fun(s,
printf("The result is:%1d/n",t);
}
问答题请编写函数fun,该函数的功能是:将s所指字符串中ASCII码值为偶数的字符删除,串中剩余字符形成一个新串放在t所指的数组中。
例如,若s所指字符串中的内容为“ABCDEFG12345”,其中字符B的ASCII码值为偶数,字符2的ASCII码值为偶数,都应当删除,其他依此类推。最后t所指的数组中的内容应是“ACEG135”。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
试题程序:
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <conio.h>
void fun(char*s,char t[])
{
}
void main()
{
char s[100],t[100];
system("CLS");
printf("\nPlease enter string S:");
scanf("%s",s);
fun(s,t);
printf("\nThe result is:%s\n",t);
}
问答题填空题
请补充main函数,该函数的功能是:从键盘输入一个字符串并保存在字符str1中,把字符串str1中下标为偶数的字符保存在字符串str2中并输出。例如,当str1=“cdefghij”,则str2=“cegi”。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun()的横线上填入所编写的若干表达式或语句。
试题程序:
#include
#include
#define LEN 80
main()
{
char str1[LEN],str2[LEN];
char *p1=str1,*p2=str2;
int i=0,j=0;
clrscr();
printf("Enter the string:/n");
scanf(【1】);
printf("***the origial string***/n");
while(*(p1+j))
{
printf("【2】",*(p1+j));
j++;
}
for(i=0;i
问答题规定输入的字符串中只包含字母和*号。请编写函数fun,其功能是:将字符串尾部的*号全部删除,前面和中间的*号不动。 例如,字符串中的内容为“****A*BC*DEF*G*******”,删除后,字符串中的内容应当是“****A*BC*DEF*G”。在编写函数时,不得使用C语言提供的字符串函数。 注意:部分源程序给出如下。 请勿改动主函数main和其他函数中任何内容,仅在函数fun的花括号中填入你编写的若干语句。 试题程序: #include<stdio.h> #include<conio.h> voidfun(char*a) void main() char s[81]; printf("Enter a string:/n"); gets(s); fun(s); printf("The string after deleted:/n"); puts(s);
问答题简单应用
给定程序MODI1.C中,函数fun 的功能是判断整数n是否是“完数”。当一个数的因子之和恰好等于这个数本身时,就称这个数为“完数”。例如:6的因子包括1、2、3,而6=1+2+3,所以6是完数。如果是完数,函数返回值为1,否则函数返回值为0。数组a中存放的是找到的因子,变量k中存放的是因子的个数。
请改正函数fun中指定部位的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
#include
int fun(int n, int a[], int *k)
{ int m=0, i, t;
t = n;
/**********found**********/
for( i=0; i
问答题下列给定程序中,fun函数的功能是:求表达式s=aa…aa-…-aaa-aa-a(此处aa…aa表示n个a,a和n的值在1~9)。 例如,a=3,n=6,则以上表达式为: s=333333-33333-3333-333-33-3 其值是296298。 a和n是fun函数的形参,表达式的值作为函数值传回main函数。 请改正程序中的错误,使它能计算出正确的结果。 注意:不要改动main函数,不得增行或删行,也不得更改程序的结构! 试题程序: #include<sfdio.h> long fun(int a,int n) int j; /********found********/ long s=0,t=1; for(i=0;j<n;j++) t=t*10+a; s=f; for(j=1;j<n;j++) /********found********/ t=t%10 s=s-t; return(s); main() int a,n; printf("/nPlease enter a and n:"); scanf("%d%d", printf("The value of function is:%ld/n",fun(a,n));
