问答题给定程序中已建立一个带有头结点的单向链表,
链表中的各结点按结点数据域中的数据递增有序链
接。函数fun的功能是:把形参x的值放入一个新结
点并插入到链表中,插入后各结点数据域的值仍保持
递增有序。
请在程序的下划线处填入正确的内容并把下划
线删除,使程序得出正确的结果。
注意:源程序存放在考生文件夹下的BLANK1.C中。
不得增行或删行,也不得更改程序的结构!
#include
#include
#define N 8
typedef struct list
{ int data;
struct list *next;
} SLIST;
void fun(SLIST *h,int x)
{SLIST *p,*q,*s;
s=(SLIST *)malloc(sizeof(SLIST));
/******** **found* *********/
s->data=【1】;
q=h;
p=h->next;
while(p!=NULL
p=p->next;
}
s->next=p;
/**********found**********/
q->next=【3】;
}
SLIST *creatlist(int *a)
{SLIST *h,*p,*q; int i;
h=p=(SLIST*)malloc(sizeof(SLIST));
for(i=0; idata=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",
fun(head,x);
printf ("/nThe list after inserting:
/n"); outlist(head);
}
问答题编写函数fun(),其功能是计算:s作为函数值返回。在C语言中可调用log(n)函数求ln(n)。log函数的引用说明为:doublelog(doublex)。例如,若m的值为20,则fun()函数值为6.506583。注意:部分源程序给出如下。请勿改动main()函数和其他函数中的任何内容,仅在函数fun()的花括号中填入你编写的若干语句。试题程序:#include<stdlib.h>#include<conio.h>#include<stdio.h>#include<math.h>doublefun(intm){}voidmain(){system("CLS");printf("%f/n",fun(20));}
问答题函数fun的功能是:根据所给的年、月、日,计算出该日是这一年的第几天,并作为函数值返回。其中函数isleap用来判别某一年是否为闰年。 例如,若输入:2008 5 1,则程序输出:2008年5月1日是该年的第122天。 请在程序的下划线处填入正确的内容,并把下划线删除,使程序得出正确的结果。 注意:源程序存放在考生文件夹下的BLANK1.C中。 不得增行或删行,也不得更改程序的结构!1 #include<stdio.h>2 int isleap(int year)3 {int leap;4 leap=(year%4==0 &&year%100 !=0|| year%400==0);5 /**********found**********/6 return__(1)__;7 }8 int fun(int year,int month,int day) {int {table[13]={0,31,28,31,30,31,9 30,31,31,30,31,30,31};10 int days=0,i;11 for(i=1;i<month;i++)12 days=days+table[i];13 /**********found**********/14 days=days+__(2)__;15 if(isleap(year)&&month>2)16 /**********found**********/17 days=days+__(3)__;18 return days;19 }20 main()21 { int year,month,day,days;22 printf(''请输入年、月、日:'');23 scanf(''%d%d%d'',&year,&month,& day);24 days =fun(year,month,day);25 printf(''%d年%d月%d日是该年的第%d天\n'',year,month,day,days);26 }
问答题规定输入的字符串中只包含字母和*号。请编写函数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> void fun(char *a,int n) { } main() { char s[81];int n;void NONO(); printf("Enter a string:\n");gets(s); printf("Enter n:");scanf("%d",&n); fun(s,n); printf("The string after deleted:\n"); puts(s); NONO(); } void NONO() (/*本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。*/ FILE *in,*out; int i,n;char s[81]; in=fopen("in.dat","r"); out=fopen("out.dat","w"); for(i=0;i<10;i++) { fscanf(in,"%s",s); fscanf(in,"%d",&n); fun(s,n); fprintf(out,"%s\n",s); } fclose(in); fclose(out); }
问答题给定程序中,函数fun的功能是将a和b所指的两个字符串分别转换成面值相同的整数,并进行相加作为函数值返回,规定字符串中只含9个以下数字字符。
例如,主函数中输入字符串¨32486”和”12345”,在主函数中输出的函数值为44831。
请在程序的下画线处填入正确的内容并把下画线删除,使程序得出正确的结果。
注意:部分源程序在文件BLANK1.C中。
不得增行或删行,也不得更改程序的结构!
试题程序:
#include < stdio.h >
#include < string.h >
#include < ctype .h >
#define N 9
long ctod ( char * s.)
{ long d=0;
while (* s)
if (isdigit ( * s)) {
/*********found*********/
d=d*10 + *s 一
【1】
;
/*********found*********/
【2】
;
}
return d;
}
long fun ( char *a, char *b )
{
/*********found*********/
return
【3】
;
}
main ()
{ char s1[N] ,s2 [N] ;
do
{ printf ("Input string s1: ") ;
gets (s1) ; }
while ( str1en (s1)) >N ) ;
do
{ printf "Input string s2 : ") ;
gets (s2) ; }
while ( str1en (s2) >N ) ;
printf ( "The result is : %ld/n",
fun (s1, s2)) ;
}
问答题给定程序中,函数fun的功能是:计算形参x所指数组中N个数的平均值(规定所有数均为正数),将所指数组中小于平均值的数据移至数组的前部,大于等于平均值的数据移至x所指数组的后部,平均值作为函数值返回,在主函数中输出平均值和移动后的数据。 例如,有10个正数:46 30 32 40 6 17 45 15 48 26,平均值为:30.500000 移动后的输出为:30 6 17 15 26 46 32 40 45 48 请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。 注意:源程序存放在考生文件夹下的BLANK1.C中。 不得增行或删行,也不得更改程序的结构!1 #include<stdlib.h>2 #include<stdio.h>3 #define N 104 double fun(double *x)5 { int i,j;double av,y[N];6 av=0;7 /**********found**********/8 for(i=0;i<N; i++) av+=__1__;9 for(i=j=0; i<N;i++)10 if(x[i]<av){11 /**********found**********/12 y[j]=x[i];x[i]=-1;_2__;}13 i=0;14 while(i<N)15 { if(x[i]!=-1)y[j++]=x[i];16 /**********found**********/17 __3__;18 }19 for(i=0;i<N;i++)x[i]=y[i];20 return av;21 }22 main()23 { int i;double x[N];24 for(i=0;i<N;i++){x[i]=rand()%50;printf(''%4.of'',x[i]);}25 printf(''\n'');26 printf(''\nThe average is:%f\n'',fun(x));27 printf(''\nThe result:\n'',fun(x));28 for(i=0 ; i<N;i++) printf(''%5.of'',x[i]);29 printf(''\n'');}
问答题给定程序MODI1. C中函数fun的功能是:逐个比较p、q所指两个字符串对应位置中的字符,把ASCII值大或相等的字符依次存放到c所指数组中,形成一个新的字符串。
例如,若主函数中a字符串为:aBCDeFgH,主函数中b字符串为:ABcd,则c中的字符串应为:aBcdeFgH。
请改正程序中的错误,使它能得出正确结果。注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
#include <stdio. h>
#include <string. h>
void fun(char *p, char *q, char *c)
{
/************found************/
int k=1;
/************found************/
while(*p!= *q)
{if(*p<*q) c[k]=*q;
else c[k]=*p;
if(*p) p++;
if(*q) q++;
k++;
}
}
main( )
{char a[10]="aBCDeFgH",
b[10]="ABcd", c[80]={"/0");
fun(a, b, c);
printf("The string a: ");
puts(a);
printf("The string b: ");
puts(b);
printf("The result: ");
puts(c);
}
问答题请编写一个函数fun,它的功能是:将SS所指字符串中所有下标为奇数位置的字母转换为大写(若该位置上不是字母,则不转换)。例如,若输入"abc4Efg",则应输出"aBc4EFg"。注意:部分源程序在文件PROGl.C中。请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。试题程序:#include<conio.h>#include<Stdio.h>#include<string.h>#include<Stdlib.h>void fun(char*ss){}void main(){ FILE*wf; char tt[81],s[81]="abc4Efg"; system("CLS"); printf("\nPlease enter an string within 80 characters:\n"); gets(tt); printf("\n\nAfter changing,the string\n%s",tt); fun(tt); printf("\nbecomes\n%s\n",tt);/******************/ wf=fopen("out.dat","W"); fun(s); fprintf(wf,"%s",s); fclose(wf);/******************/
问答题请编写一个函数void proc(int m, int k, int xx[]),该函数的功能是:将大于整数m且紧靠m的k个素数存入所指的数组中。
例如,若输入20 6,则应输出23 29 31 37 41 43。
注意:部分源程序给出如下。
请勿改动main()函数和其他函数中的任何内容,仅在函数proc()的花括号中填入所编写的若干语句。
试题程序:
#include<stdlib.h>
#include<conio.h>
#include<stdio.h>
void proc(int m, int k, int xx[])
{
}
void main()
{
int m, n, arr[1000];
system("CLS");
printf("/nPlease enter two integers:");
scanf("%d%d",
proc(m, n, arr);
for(m=0; m<n; m++)
printf("%d", arr[m]);
printf("/n");
}
问答题编写函数,根据整型形参n的值,计算如下公式的值:
问答题请编写一个函数proc(),它的功能是:求出1~m(含m)能被7或11整除的所有整数并将其放在数组a中,通过n返回这些数的个数。
例如,若传给m的值为70,则程序输出:
7 11 14 21 22 28 33 35 42 44 49 55 56 63 66 70
注意:部分源程序给出如下。
请勿改动main()函数和其他函数中的任何内容,仅在函数proc()的花括号中填入所编写的若干语句。
试题程序:
#include<stdlib.h>
#include<conio.h>
#include<stdio.h>
#define N 100
void proc(int m, int*a, int*n)
{
}
void main()
{
int arr[N], n, k;
system("CLS");
proc(70, art,
for(k=0; k<n; k++)
if((k+1)%20==0)//每行输出20个数
{printf("%4d", arr[k]);
printf("/n");
}
else
printf("%4d", arr[k]);
printf("/n");
}
问答题给定程序中,函数fun的功能是计算下式
例如:若形参e的值为1e-3,函数的返回值为0.551690。
请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。
注意:源程序存放在考生文件夹下的BLANK1.C中。
不得增行或删行,也不得更改程序的结构!
给定源程序:
#include
double fun(double e)
{ int i, k; double s, t, x;
s=0; k=1; i=2;
/**********found**********/
x=__1__/4;
/**********found**********/
while(x __2__ e)
{ s=s+k*x;
k=k* (-1);
t=2*i;
/**********found**********/
x=__3__/(t*t);
i++;
}
return s;
}
main()
{ double e=1e-3;
printf("/nThe result is: %f/n",fun(e));
}
问答题学生的记录由学号和成绩组成,N名学生的数据已在主函数中放入结构体数组s中,请编写函数fun,它的功能是:按分数的高低排列学生的记录,高分在前。 [注意] 部分源程序给出如下。请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。 [试题源程序] #include<stdio.h> #define N 16 typedef struct char num[i0]; int s; STREC; int fun(STREC a[]) 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; FILE *out; fun(s); printf("The data after sorted:/n"); for(i=0;i<N; i++) if((i)%4==0) printf("/n"); printf("%s%4d", s[i]. num, s[i].s); printf("/n");
问答题请编写一个函数void fun(char *tt,int pp[]),统计在tt所指字符串中'''a'''到'''z'''26个小写字母各自出现的次数,并依次放在pp所指数组中。 例如,当输入字符串:abcdefgabcdeabc后,程序的输出结果应该是: 3 3 3 2 2 1 1 0 0 0 0 0 0 0 O 0 0 0 0 0 0 0 0 0 0 0 注意:部分源程序在文件PROG1.C中。 请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。1 #include<stdio.h>2 #include<string.h>3 void fun(char *tt,int pp[])4 {56 }7 main()8 { char aa[1000];9 int bb[26],k;10 void NONO();11 printf(''\nPlease enter a char string:'');scanf(''%s'',aa);12 fun(aa,bb);13 for(k=0 ; k<26;k++) printf(''%d'',bb[k]);14 printf(''\n'');15 NONO();16 }17 void NONO()18 {/*本函数用于打开文件,输入测试数据,调用fun函数,输出数据,关闭文件。*/19 char as[1000];20 int bb[26],k,i;21 FILE *rf,*wf;22 rf=fopen(''in.dat'',''r'');23 wf=fopen(''out.dat'',''w'');24 for(i=0;i<10;i++) {25 fscanf(rf,''%s'',aa);26 fun(aa,bb);27 for(k=0;k<26;k++) fprintf(wf,''%d'',bb[k]);28 fprintf(wf,''\n'');29 }30 fclose(rf);31 fclose(wf);32 }
问答题学生的记录由学号和成绩组成,N名学生的数据己在主函数中放入结构体数组s中,请编写函数fun(),它的功能是:把分数最低的学生数据放在h所指的数组中。注意:分数低的学生可能不只一个,函数返回分数最低学生的人数。 注意:部分源程序给出如下。 请勿改动主函数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]="GA005",82,"GA003",75, "GA002",85,"GA004",78,"GA001",95, "GA007",62,"GA008",60,"GA006",85, "GA015",83,"GA013",94,"GA012",78, "GA014",97,"GA011",60,"GA017",65, "GA018",60,"GA016",74; 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].mum,h[i].s); /*输出最低分学生的学号和成绩*/ printf("/n"); out=fopen("out19.dat","w"); fprintf(out,"%d/n",n); for(i=0;i<n;i++); fprintf(out,"%4d/n",h[i].s); fclose(out);
问答题给定程序中,函数fun的功能是:利用指针数组对形参ss所指字符串数组中的字符串按由长到短的顺序排序,并输出排序结果。ss所指字符串数组中共有N个字符串,且串长小于M。 请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。 注意:源程序存放在考生文件夹下的BLANK1.C中。 不得增行或删行,也不得更改程序的结构!1 #include<stdio.h>2 #include<string.h>3 #define N 54 #define M 85 void fun(char(*ss)[M])6 { char *ps[N],*tp;int i,j,k;7 for(i=0;i<N;i++)ps[i]=ss[i];8 for(i=0;i<N-1;i++) {9 /**********found**********/10 k= __1__;11 for(j=i+1;j<N;j++)12 /**********found**********/13 if(strlen(ps[k] ) <strlen(__2__))k=j;14 /**********found**********/15 tp=ps[i];ps[i]=ps[k];ps[k]=__3__;16 }17 printf(''\nThe string after sorting by length:\n\n'');18 for(i=0;i<N;i++)puts(ps[i]);19 }20 main()21 {char ch[N][M]={''red'',''green'',''blue'',''yellow'',''black''};22 int i;23 printf(''\nThe original string\n\n'');24 for(i=0;i<N;i++)puts(ch[i]); printf(''\n'');25 fun(ch);}
问答题
给定程序MODI1.C中函数fun的功能是:求整数x的y次方的低3位值。例如,整数5的6次方为15625,此值的低3位值为625。
请改正函数fun中指定部位的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!
#include <stdio.h>
long fun(int x,int y,long *p)
{ int i;
long t=1;
/*************found*************/
for(i=1;i<y;i++)
t=t*x;
*p=t;
/*************found*************/
t=t/1000;
return t;
}
main()
{ long t,r;int x,y;
printf("/nInput x and y:");scanf("%ld%ld",
t=fun(x,y,
printf("/n/nx=%d,y=%d,r=%ld,last=%ld/n/n",x,y,r,t);
}
问答题函数fun的功能是:将s所指字符串中ASCII值为奇数的字符删除,串中剩余字符形成一个新串放在t所指的数组中。
例如,若s所指字符串中的内容为:“ABCDE FG12345”,其中字符A的ASCII码值为奇数、…、字符1的ASCII码值也为奇数、…都应当删除,其他依此类推。最后t所指的数组中的内容应是“BDF24”。
注意:部分源程序存在文件PROG1.C中。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入编写的若干语句。
给定源程序:
#include <stdio.h>
#include <string.h>
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);
}
问答题请编写函数void proc(int x,int pp[],int*n),它的功能是:求出能整除x且不是偶数的各整数,并按从小到大的顺序放在pp所指的数组中,这些除数的个数通过形参n返回。
例如,若x中的值为50,则有3个数符合要求,它们是1,5,25。
注意:部分源程序给出如下。
请勿改动main()函数和其他函数中的任何内容,仅在函数proc()的花括号中填入所编写的若干语句。
试题程序:
#include<conio.h>
#include<stdio.h>
#include<stdlib.h>
void proc(int x, int pp[], int*n)
{
}
void main()
{
int x, arr[1000], n, i;
system("CLS");
printf("/nPlease enter an integer
number: /n");
scanf("%d",
proc(x, arr,
for(i=0; i<n; i++)
printf("%d", arr[i]);
printf("/n");
}
问答题已知一个数列从0项开始的前3项为0,0,1,以后的各项都是其相邻的前3项之和。下列给定的程序中,函数proc()的功能是:计算并输出该数列前n项的和sum。n的值通过形参传入。例如,当n=20时,程序的输出结果应为42762.000000。
请修改程序中的错误,使它能得到正确结果。
注意:不要改动main()函数,不得增行或删行,也不得更改程序的结构。
试题程序:
#include<stdlib.h>
#include<conio.h>
#include<stdio.h>
double proc(int n)
{
double sum, s0, s1, s2, s;
int k;
sum=1.0;
if(n<=2)
sum=0.0;
s0=0.0;
s1=0.0;
s2=1.0;
//****found****
for(k=4; k<n; k++)
}
{
s=s0+s1+s2;
sum+=s;
s0=s1;
s1=s2;
//****found****
s2=s;
return sum;
}
void main()
{
int n;
system("CLS");
printf("Input N=");
scanf("%d",
printf("%f/n", proc(n));
}