问答题编写一个函数,输入n个字符串,串与串之间以回车键分隔,找出最短字符串中第一个字符串,传回该串地址(用一个新串“*”作为结束输入的标志)。 注意:部分源程序已给出。 请勿改动主函数main和其他函数中的任何内容,仅在函数proc的花括号中填入所编写的若干语句。 试题程序: #include<stdio.h> #include<string.h> #include<conio.h> char*fun(char(*s)[100],int num) main() char str[10][100],*min; int n,i=0; FILE*out:printf("input strings with'*'asend:"); gets(str[i]); strcpy(str[3],"some"); strcpy(str[4],"tool?!?"; fprintf(out,"%s",fun(str,5)); puts(str[i]); while(!strcmp(str[i],"*")==0) i++; gets(str[i]); puts(str[i]); n=1; min=fun(str,n); printf("/nmin=%s/n",min); out=open("outfile.dat","w"); strepy(str[0],"just,"); strcpy(str[1],"a"); strcpy(str[2],"test"); fclose(out);
问答题人员的记录由编号和出生年、月、日组成,N名人员的数据已在主函数中存入结构体数组std中。函数fun的功能是:找出指定出生年份的人员,将其数据放在形参k所指的数组中,由主函数输出,同时由函数值返回满足指定条件的人数。 请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。 注意:源程序存放在考生文件夹下的BLANK1.C中。 不得增行或删行,也不得更改程序的结构!1 #include<stdio.h>2 #define N 83 typedef struct4 { int num;5 int year,month,day;6 } STU;7 int fun(STU *std, STU *k, int year)8 { int i,n=0;9 for(i=0;i<N;i++)10 /**********found**********/11 if(__1__==year)12 /**********found**********/13 k[n++]=__2__;14 /**********found**********/15 return( __3__);16 }17 main()18 {STU std[N]={{1,1984,2,15},{2,1983,9,21},{3,1984,9,1},{4,1983,7,15},{5,1985,9,28},{6,1982,11,15},{7,1982,6,22},{8,1984,8,19}};19 STU k[N];int i,n,year;20 printf(''Enter a year : '');scanf(''%d'',&year);21 n=fun(std,k,year);22 if(n==0)23 printf(''\nNo petson was born\n%d\n'',year);24 else25 { printf(''\nThese persons were born\ n%d\n'',year);26 for(1=0; i<n;i++)27 printf(''%d %d-%d-%d\n'', k[i].num,k[i].year,k[i].month,k[i].day);28 }29 }
问答题函数fun的功能是:输出a所指数组中的前n个数据,要求每行输出5个数。
请在程序的下画线处填入正确的内容并把下画线删除,使程序得出正确的结果。
注意:源程序存放在考生文件夹下的BIANK1.C中。不得增行或删行,也不得更改程序的结构!
试题程序:
#include < stdio.h >
#include < stdlib.h >
void fun(int*a,int 13)
{int i;
for(i=0;i < n;i++)
{
/*********found*********/
if(
【1】
==0)
/*********found*********/
printf("
【2】
");
/*********found*********/
printf("%d",
【3】
);
}
}
main()
{int a[100]={0),i,n;
n=22;
for(i=0;i < n;i++)
a[i]=rand()%21;
fun(a,n);
printf("/n");
}
问答题下列程序定义了N×N的二维数组,并在主函数中赋值。请编写一个函数fun(),函数的功能是:求数组周边元素的平方和,并作为函数值返回给主函数。例如,若数组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; j++) printf("%4d", a[i][j]); printf("/n"); s=fun(a); printf("*****THE RESULT*****/n"); printf("The sum is: %d/n", s);
问答题printf"Input 2th string: ");
问答题下列给定程序中,函数fun的功能是:计算如下公式直到≤10-3,并且把计算结果作为函数值返回。例如,若形参e的值为1e一3,则函数返回值为0.551690。请在程序的下画线处填入正确的内容并将下画线删除,使程序得出正确的结果。注意:部分源程序给出如下。不得增行或删行,也不得更改程序的结构!试题程序:#include<stdio.h>doublefun(doublee){inti,k;doubles,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++;}returns;}main(){doublee=1e一3;printf("\nTheresultis:%f\n",fun(e));}
问答题程序定义了N×N的二维数组,并在主函数中自动赋值。请编写函数fun(inta[][N],intn),该函数的功能是:使数组左下半三角元素中的值乘以n。例如,若n的值为3,a数组中的值为:则返回主程序后a数组中的值应为:注意:部分源程序给出如下。请勿改动函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。试题程序:#include<stdio.h>#include<conio.h>#include<stdlib.h>#defineN5voidfun(inta[][N],intn){}main(){inta[N][N],n,i,j;printf("*****Thearray*****\n");for(i=0;i<N,i++){for(j=0;j<N;j++){a[i][j]=rand()%10;printf("%4d",a[i][j]);}printf("\n");}n=rand()%4;printf("n=%4d\n",n);fun(a,n);printf("*****THERESULT*****\n");for(i=0;i<N;i++){for(j=0;j<N;j++)printf("%4d",a[i][j]);printf("\n");}}
问答题请编写一个函数fun,它的功能是将一个表示正整数的数字字符串转换为一个整数(不得调用C语言提供的将字符串转换为整数的函数)。例如,若输入字符串“1234”,则函数把它转换为整数值1234。函数fun中给出的语句仅供参考。
注意:部分源程序存在文件PROG1.C中。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入编写的若干语句。
给定源程序如下。
#include<stdio.h>
#include<string.h>
long fun(char
*
p)
{
/*以下代码仅供参考*/
int i,len;/*len为串长*/
long x=0:
len=strlen(p);
/★以下完成数字字符串转换为一个数字。
注意:字符"0"不是数字0★/
return x;
}
main(),/*主函数*/
{ char s[6];
long n;
printf("Enter a string:/n");
gets(s);
n=fun(s);
printf("%ld/n",n);
}
问答题下列给定的程序中,函数fun的功能是:计算并输出k以内最大的10个能被13或17整除的自然数之和。k的值由主函数传入,若k的值为500,则函数的值为4622。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!
试题程序:
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
int fun(int k)
{
int m=0,mc=0,j;
while((k>2)&&(mc<10))
{
/********found********/
if((k%13=0)||(k%17=0))
{
m=m+k;mc++;
}
k--;
/********found********/
return m;
}
}
void main()
{system("CLS");
printf("%d/n",fun(500));
}
问答题给定程序MODI1.C中函数fun的功能是:删除P所指字符串中的所有空白字符(包括制表符、回车符及换行符)。
输入字符串时用"#"结束输入。
请改正程序中的错误,使它能输出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
#include<string.h>
#include<stdio.h>
#include<ctype.h>
fun(char*P)
{int i,t;char c[80];
/**********found**********/
For(i=0,t=0;p[i];i++)
if(!isspace(*(p+i)))c[t++]=p[i];
/**********found**********/
c[t]="/0";
strcpy(p,c);
}
main()
{char c,s[80];
int i=0;
printf("Input a string:");
c=getchar();
while(c!="#")
{s[i]=c;i++;c=getchar();)
s[i]="/0";
fun(s);
puts(s);
}
问答题函数fun的功能是:将一副扑克牌编号为1,2,3,…,53,54,以某种特定的方式洗牌,这种方式是将这副牌分成两半,然后将它们交叉,并始终保持编号为1的牌在最上方,如第一次这样洗牌后的结果为:1,28,2,29,…,53,27,54。两次洗牌后的结果为:1,41,28,15,2,42…,53,40,27,14,54程序的功能是:输出经过n次这样洗牌后的结果。请在程序的下画线处填入正确的内容,并把下画线删除,使程序得出正确的结果。注意:源程序存放在考生文件夹下的BLANK1.C中。不得增行或删行,也不得更改程序的结构!试题程序:#include<stdio.h>void fun(int a[55],int n){int i,k;/**********found**********/int【1】[55];for(i=0;i<n;i++){for(k=1;k<=27;k++){b[2*k-1]=a[k];/**********found**********/b[【2】*k]=a[k+27];}for(k=1;k<=54;k++)/**********found**********/a[k]=【3】;}}main(){int m,a[55],i;for(i=1;i<55;i++)a[i]=i;pfinff("请输入洗牌次数:");scanf("%d",&m);fun(a,m);for(i=1;i<55;i++)printf("%d,",a[i]);printf("\n");}
问答题给定函数MODI1.C中函数fun的功能是:将一个由八进制数字字符组成的字符串转换为与其面值相等的十进制整数。规定输入的字符串最多只能包含5位八进制数字字符。
例如,若输入:77777,则输出将是:32767。
请改正程序中的错误,使它能得出正确结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
#include
#include
#include
int fun(char*p)
{ int n;
/**********found**********/
n=*p一'o';
p++;
while(*P!=0){
/************found************/
n=n*8+*p一'o';
p++;
}
return n;
}
main()
{ char s[6];int i;2nL n;
printf("Enter a string(ocatal
digits):"); gets(s);
if(strlen(s)>5){printf("Error:
String too longer!/n/n");exit(0);)
for(i=0;s[i];i++)
if(s[i]'7')
{print;f("Error:%c not is
ocatal digits!/n/n",s[i]);exit:(0);)
print;f("The original string:
"); puts(s);
n=fun(s);
printf("/n%s is convered to
integer number: %d/n/n",s,n);
}
问答题编写函数fun,其功能是:将s所指字符串中除了下标为奇数同时ASCII码值也为奇数的字符之外,其余的所有字符全部删除,串中剩余字符所形成的一个新串放在t所指的数组中。例如,若s所指字符串的内容为“ABCDEFG12345”,其中字符A的ASCII码值为奇数,但所在元素的下标为偶数,因此需要删除;而字符1的ASCII码值为奇数,所在数组中的下标也为奇数,因此不应当删除,其他依此类推。最后t所指数组中的内容应为“135”。注意:部分源程序给出如下。请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。试题程序:#include<conio.h>#include<stdio.h>#include<string.h>void fun(char *s,char t[]){}main(){ char s[100],t[100]; printf("knPlease enter string s:"); scanf("%s",s); fun(s,t); printf("knThe result is:%s\n",t);}
问答题下列给定程序中,函数fun的功能是:计算如下公式直到≤10一3,并且把计算结果作为函数值返回。例如,若形参e的值为1e一3,则函数返回值为0.551690。请在程序的下画线处填入正确的内容并将下画线删除,使程序得出正确的结果。注意:部分源程序给出如下。不得增行或删行,也不得更改程序的结构!试题程序:#include<stdio.h>doublefun(doublee){inti,k;doubles,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++;}returns;}main(){doublee=1e一3;printf("/nTheresultis:%f/n",fun(e));}
问答题给定程序的功能是:调用函数fun将指定源文件中的内容复制到指定的目标文件中,复制成功时函数返回值为1,失败时返回值为0。在复制的过程中,把复制的内容输出到终端屏幕。主函数中源文件名放在变量sfname中,目标文件名放在变量tfname中。
请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。
注意:源程序存放在考生文件夹下的BLANK1.C中。
不得增行或删行,也不得更改程序的结构!
#include
#include
int fun(char *source, char
*target)
{FILE *fs,*ft; char ch;
/********found* *********/
if ((fs=fopen(source,【1】))
==NULL)
return 0;
if ((ft=fopen(target,"w"))==NULL
)
return 0;
printf ("/nThe data in
file :/n");
ch=fgetc(fs);
/*********found**********/
while (! feof (【2】) )
{ putchar(ch);
/********** found* *********/
fputc (ch,【3】) ;
ch=fgetc(fs);
}
fclose(fs); fclose(ft);
printf("/n/n");
return 1;
}
main ()
{ char sfname[20] ="myfilel",
tfname[20]="myfile2";
FILE *myf; int i; char c;
myf=fopen(sfname,"w");
printf("/nThe original
data :/n");
for(i=l; i<30; i++)
{ c='A'+rand() %25;
fprintf(myf, "%c",c);
printf ("%c",c);}
fclose (myf) ,-printf ("/n/n");
if(fun(sfname, tfname))
printf ("Succeed!");
else printf("Fail!");
}
问答题下列给定程序中函数fun的功能是:用冒泡法对6个字符串按由小到大的顺序进行排序。请改正程序中的错误,使它能得出正确的结果。注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!试题程序:#include<stdlib.h>#include<string.h>#include<conio.h>#include<stdio.h>#define MAXLINE 20fun(char*pstr[6]){ int i,j; char*P; for(i=0;i<5;i++) { /*********found*********/ for(j=i+1,j<6,j++) { if(strcrnp(*(pstr+i),(pstr+j))>0) { P=*(pstr+i); /*********found*********/ *(pstr+i)=pstr+j; *(pstr+j)=p; } } }} void main() { int i; char*pstr[6],str[6][MAxLINE]; system("CLS"); for(i=0;i<6;i++) pstr[i]=str[i]; printf("\nEnter 6 string(1 string at each line):\n"); for(i=0;i<6;i++) scanf("%s",pstr[i]); fun(pstr); printf("The strings after sorting:\n"); for(i=0;i<6;i++) printf("%s\n",pstr [i]); }
问答题请编写函数fun(),对长度为7个字符的字符串,除首、尾字符外,将其余5个字符按ASCII码值升序排列。
例如:原来的字符串为BdsihAd,则排序后输出为 BAdhisd。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
#include <stdio.h>
#include <ctype.h>
#include <conio.h>
int fun(char*s,int num)
{
}
main()
{
char s[10];
clrscr();
printf("输入7个字符的字符串:");
gets(s);
fun(s,7);
printf("/n%s",s);
}
问答题给定程序中,函数fun的功能是将带头节点的单向链表结点数据域中的数据从小到大排序。即若原链表结点数据域从头至尾的数据为:10、4、2、8、6,排序后链表结点数据域从头至尾的数据为:2、4、6、8、10。 请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。 注意:源程序存放在考生文件夹下的BLANK1.C中。 不得增行或删行,也不得更改程序的结构!1 #include<stdio.h>2 #include<stdlib.h>3 #define N 64 typedef struct node{5 int data;6 struct node *next;7 } NODE;8 void fun(NODE *h)9 { NODE *p,*q;int t;10 /**********found**********/11 p=___1__;12 while(p) {13 /**********found**********/14 q=__2__;15 while(q) {16 /**********found**********/17 if(p->data__3__q->data)18 { t=p->data;p->data=q->data;q->data=t;}19 q=q->next;20 }21 p=p->next;22 }23 }24 NODE *creatlist(int a[])25 { NODE *h,*p,*q;int i;26 h=(NODE *)malloc(sizeof(NODE));27 h->next=NULL;28 for(i=0;i<N;i++)29 { q=(NODE *)malloc(sizeof(NODE));30 q->data=a[i];31 q->next=NULL;32 if(h->next==NULL)h->next=p=q;33 else{p->next=q;p=q;}34 }35 return h;36 }37 void outlist(NODE *h)38 { NODE *p;39 p=h->next;40 if(p==NULL)printf(''The list is NULL!\n'');41 else42 { printf(''\nHead'');43 do44 {printf(''->%d'',p->data);p=p->next;}45 while(p!=NULL);46 printf(''->End\n'');47 }48 }49 main()50 { NODE *head;51 int a[N]={0,10,4,2,8,6};52 head=creatlist(a);53 printf(''\nThe original list:\n'');54 outlist(head);55 fun(head);56 printf(''\nThe list after sorting:\n'');57 outlist(head);58 }
问答题函数fun的功能是:将两个两位数的正整数a、b合并成一个整数放在c中。合并的方式是:将a数的十位和个位数依次放在c数的千位和十位上,b数的十位和个位数依次放在c数的百位和个位上。
例如,当a=45,b=12时,调用该函数后c=4152。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
试题程序:
#include<conio.h>
#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:%d/n", c);
}
问答题下列给定程序中,函数fun的功能是:在形参ss所指字符串数组中查找与形参t所指字符串相同的串,找到后返回该串在字符串数组中的位置(即下标值),若未找到则返回-1。ss所指字符串数组中共有N个内容不同的字符串,且串长小于M。请在程序的下划线处填入正确的内容并将下划线删除,使程序得出正确的结果。注意:部分源程序在文件BLANK1.C中。不得增行或删行,也不得更改程序的结构!#include<stdio.h>#include<string.h>#define N5#define M8int fun(char(*ss)[M],char*t){int i;/**********found**********/for(i=0;i<【1】;i++)/**********found**********/if(stremp(ss[i],t)==0)return【2】;return-1;}main(){char ch[N][M]={"if","while","switch","int","for"},t[M];int n,i;printf("\nThe original string\n\n");for(i=0;i<N;i++)puts(eh[i]);printf("\n");printf("\nEnter a string for search:");gets(t);n=fun(ch,t);/**********found**********/if(n==【3】)printf("\nDon't found!\n");else printf("\nThe position is%d.\n",n);}
