问答题编写函数fun,其功能是:从字符串中删除指定的字符。同字母的大、小写按不同字符处理。 注意:部分源程序给出如下。 请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。 试题程序: #include <stdio.h> void fun(char s[], int c) main() fstatic, char str[]="turbo c and borland c++"; char ch; printf("原始字符串:%s/n",str); printf("输入一个字符:/n"); scanf("%c", &ch); fun(str, ch); printf("str[]=%s/n", str); strcpy (str, "turbo c and borland c++"); fun(str, 'a');
问答题请编写函数fun,功能是:判断形参n中的正整数是几位数(输入数据的位数不超过4位),并将结果通过函数值返回。 例如:若输入的数据为123,则输出结果为:输入的数字是3位。 注意:部分源程序存在PROG1.C中,请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。1 #include<stdio.h>2 void NONO();3 int fun(int n)4 {5 }6 main()7 {int n,place;8 do{9 printf(''请输入一个4位以内的正整数:'');10 scanf(''%d'',&n);11 } while(n<0 || n>9999);12 place=fun(n);13 printf(''输入的数字是%d位\n'',place);14 NONO();15 }16 void NONO()17 {/*本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。*/18 FILE *fp,*wf;19 int i,n,place;20 fp=fopen(''in.dat'',''r'');21 wf=fopen(''out.dat'',''w'');22 for(i=0;i<10;i++)23 {fscanf(fp,''%d'',&n);24 place=fun(n);25 fprintf(wf,''%d\n'',place);26 }27 fclose(fp);28 fclose(wf);29 }
问答题给定程序中,函数fun的功能是:
将形参s所指字符串中的数字字符转换成对应的数值,计算出这些数值的累加和作为函数值返回。
例如,形参s所指的字符串为abs5def126jkm8,程序执行后的输出结果为22。
请在程序的下画线处填入正确的内容并把下画线删除,使程序得出正确的结果。
注意:部分源程序在文件BLANK1.C中。
不得增行或删行,也不得更改程序的结构!
试题程序:
#include < stdio.h >
#include < string.h >
#include < ctype.h >
int fun(char*s)
{int sum=0;
while(*s){
/*********found*********/
if(isdigit(*s))
sum+=*s一
【1】
;
/*********found*********/
【2】
;
}
/*********found*********/
return
【3】
;
}
main()
{char s[81];int n;
pr2ntf("/nEnter a string:/n/n");
gets(s);
n=fun(s);
printf("/nThe result is:%d/n/n",n);
}
问答题假定输入的字符串中只包含字母和*号。请编写函数fun,它的功能是:使字符串中尾部的*号不得多于n个;若多于n个,则删除多余的*号;若少于或等于n个,则什么也不做, 字符串中间和前面的*号不删除。
例如,字符串中的内容为:****A*BC*DEF*G*******,若n的值为4,删除后,字符串中的内容应当是:****A*BC*DEF*G****;若n的值为7,则字符串中的内容仍为:****A*BC*DEF*G*******。n的值在主函数中输入。在编写函数时,不得使用C语言提供的字符串函数。
注意: 部分源程序在文件PROG1.C中。
请勿改动主函数main和其它函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
给定源程序:
#include
void fun( char *a,int n )
{
}
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);
NONO();
}
问答题给定程序中,函数fun的功能是将带头结点的单向链表逆置,即若原链表中从头至尾结点数据域依次为2、4、6、8、10,逆置后,从头至尾结点数据域依次为10、8、6、4、2。
请在程序的下画线处填入正确的内容并把下画线删除,使程序得出正确的结果。
注意:部分源程序给出如下。
不得增行或删行,也不得更改程序的结构!
试题程序:
#include<stdio.h>
#include<stdlib.h>
#define N 5
typedef struct node{
int data;
struct node * next;
}NODE;
void fun(NODE*h)
{ NODE*P,*q,*r;
/*********found*********/
P=h->
【1】
;
/*********found*********/
if(p==
【2】
)return;
q=P->next;
P->next=NULL;
while(q)
{r=q->next;q->next=p;
/*********found*********/
p=q;q=
【3】
;
}
h->next=P;
}
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("\nttead");
do
{printf("->%d",P->data);
p=P->next;)
while(P!=NULL);
printf("->End\n");
}
}
main()
{ NODE*head;
int a[N]={2,4,6,8,10};
head=creatlist(a);
printf("\nThe original list:\n");
outlist(head);
fun(head);
printf("\nThe list after inverting:\n");
outlist(head);
}
问答题给定程序MODI1.C中函数 fun 的功能是:计算n!。
例如,给n输入5,则输出120.000000。
请改正程序中的错误,使程序能输出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!
给定源程序:
#include
double fun ( int n )
{ double result = 1.0 ;
if n = = 0
return 1.0 ;
while( n >1
}
main ( )
{ int n ;
printf("Input N:") ;
scanf("%d",
printf("\n\n%d! =%lf\n\n", n, fun(n)) ;
}
问答题函数fun的功能是:将s所指字符串中除下标为偶数同时ASCII码值也为偶数的字符外,其余的全部删除;字符串中剩余字符所形成的新串放在t所指的数组中。
例如,若s所指字符串中的内容为“ABCDEFG123456”,其中字符A的ASCII码值为奇数,因此应当删除;字符B的ASCII码值为偶数,但在数组中的下标为奇数,因此也应当删除;字符2的ASCII码值为偶数,在数组中的下标也为偶数,因此不应当删除,其他依此类推。最后t所指的数组中的内容应是“246”。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
试题程序:
#include<stdio.h>
#include<string.h>
void fun(char*s,char t[])
{
}
void main()
{char s[100],t[100];
printf("/nPlease enter string S:");
scanf("%s",s);
fun(s,t);
printf("/nThe result is:%s/n",t);}
问答题下列给定程序中,fun函数的功能是:分别统计字符串中大写字母和小写字母的个数。 例如,给字符串s输入:AAaaBBbb123 CCcccd,则应输出: upper=6,lower=8。请改正程序中的错误,使它得出正确的结果。 注意:部分源程序在文件MODI1.C中,不要改动main函数,不得增行或删行,也不得更改程序的结构! 试题程序:#include < stdio.h >/*********found*********/void fun ( char *s, int a, int b ){ whiie (*s )if(*s >='A'&&* s < ='Z')/*********found*********/ *a=a+1;if(*s >='a'&& S < ='z')/*********found*********/ s ++ ; }}main ( ){ char s[100]; int upper = 0, lower = 0 ; printf ( "/nPlease a string : " ) ; gets ( s ); fun ( s, & upper, &lower ); printf ( " / n uppelr =% d lower=%d/n", upper, lower ) ;}
问答题请编写函数fun,其功能是:计算并输出例如,在主函数中从键盘给n输入20后,输出为:s=534.188884。注意:要求n的值大于1但不大于100。部分源程序在文件PROG1.C中。请勿改动主函数mam和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。#include#includedoublefun(intn){}main(){intn;doubles;printf("/n/nlnputn:");scanfs=fun(n);printf("/n/ns=%f/n/n",s);NONO();NONO(){/*请在此函数内打开文件,输入测试数据,调用fun函数,输出数据,关闭文件。*/FILE*rf,*wf;intn,i;doubles;rf=fopen("in.dat","r");wf=fopen("out.dat","w");for(i=0;i
问答题学生的记录由学号和成绩组成,M名学生的数据已在主函数中放入结构体数组str中,请编写函数proc(),它的功能是:把低于平均分的学乍数据放在b所指的数组中,低于平均分的学生人数通过形参n传回,平均分通过函数值返回。
注意:部分源程序给出如下。
请勿改动main()函数和其他函数中的任何内容,仅在函数proc()的花括号中填入所编写的若干语句。
试题程序:
#include<stdio.h>
#define M 8
typedef struct
{char num[10];
double s;
}
STREC;
double proc(STREC*a, STREC*b, int*n)
{
}
void main()
{
STREC str[M]={{"GA05", 85}, {"GA03", 76},
{"GA02", 69}, {"GA04", 85},
{"GA01", 91}, {"GA07", 72}, {"GA08", 64},
{"GA06", 87}};
STREC h[M];
int i, n;
double ave;
ave=proc(str, h,
printf("The %d student data which is
lower than %7.3f:/n", n, ave);
for(i=0; i<n; i++)
//输出成绩低于平均值的学生记录
printf("%s%4.1f/n", h[i].num,
h[i].s);
printf("/n");
}
问答题请编写函数fun,函数的功能是:将大于形参m且紧靠m的k个素数存入xx所指的数组中。例如,若输入17, 5,则应输出:19, 23, 29, 31, 37。函数fun中给出的语句仅供参考。
注意: 部分源程序在文件PROG1.C文件中。
请勿改动主函数main和其它函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
给定源程序:
#include
void fun(int m, int k, int xx[])
{
/* 以下代码仅供参考 */
int i, j=1, t=m+1;
while(j<=k)
{
/* 以下完成判断素数,并存放到数组xx中 */
}
}
main()
{
int m, n, zz[1000] ;
printf( "/nPlease enter two integers:") ;
scanf("%d%d",
fun( m, n, zz) ;
for( m = 0 ; m < n ; m++ )
printf("%d ", zz[m]) ;
printf("/n") ;
NONO( ) ;
}
问答题已知学生的记录由学号和学习成绩构成,N名学生的数据已存入a结构体数组中。请编写函数fun,函数的功能是找出成绩最低的学生记录,通过形参返回主函数(规定只有一个最低分)。
注意:部分源程序存在文件PROG1.C中。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入编写的若干语句。
给定源程序如下。
#include<stdio.h>
#include<string.h>
#define N 10
typedef struct ss
{ char num[10];int s;}STU;
void fun( STU a[],STU*s)
{
}
main()
{ STU a[N]={{"A01",81},{"A02",89},{"A03",66},
{"A04",87},{"A05",77},{"A06",90},{"A07",79},
{"A08",61},{"A09",80},{"A10",71}},m;
int i;
printf("*****The original data*****/n");
for(i=0;i<N;i++)
printf("No=%s Mark=%d/n",a[i].num,a[i].s);
fun (a,
printf("*****THE RESULT*****/n");
printf("The lowest:%s,%d/n",m.num,m.s);
}
问答题编写函数fun,它的功能是:计算并输出下列级数和:
1 1 1
S = ── + ── + … + ───
1×2 2×3 n(n+1)
例如,当n = 10时,函数值为:0.909091。
注意: 部分源程序在文件PROG1.C文件中。
请勿改动主函数main和其它函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
给定源程序:
#include
double fun( int n )
{
}
main() /* 主函数 */
{
printf("%f/n", fun(10));
NONO();
}
问答题下列程序定义了N×N的二维数组,并在主函数中自动赋值。请编写函数fun(inta[][N],intm),该函数的功能是使数组右上半三角元素中的值乘以m。例如,若m的值为2,a数组中的值为:则返回主程序后a数组中的值应为:注意:部分源程序给出如下。请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。试题程序:#include<stdio.h>#include<onio.h>#include<stdlib.h>#include<string.h>#defineN5voidfun(inta[][N],intm){}main(){inta[N][N],m,i,j;printf("****Thearray*****/n");for(i=0;i<N;i++){for(j=0;j<N;j++){a[i][j]=rand()%20;printf("%4d",a[i][j]);}printf("/n");}m=rand()%4;printf("m=%4d/n",m);fun(a,m);printf("THERESULT/n");for(i=0;i<N;i++){for(j=0;j<N;i++)printf("%4d",a[i][j];printf("/n");}}
问答题
给定程序MODI1.C中函数fun的功能是:用冒泡法对6个字符串按由小到大的顺序进行排序。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!
#include<stdio.h>
#include<string.h>
#define MAXLINE 20
fun(char *pstr[6])
{int i, j;
char *p;
for(i=0; i<5; i++) {
/**********found**********/
for(j=i+1, j<6, j++)
{
if(strcmp(*(pstr+i), *(pstr+j))>0)
{
p=*(pstr+i);
/**********found**********/
*(pstr+i)=pstr+j;
*(pstr+j)=p;
}
}
}
}
main()
{int i;
char*pstr[6], str[6][MAXLINE];
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:在形参指针所指的4个整数中找出最大值和最小值,最大的放在a中,最小的放在d中。
注意:部分源程序存在PROGI.C中,请勿改动主函数maln和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
#include
void NONO();
void fun (int *a,int *b,int *c,int *d)
{
}
main()
{int a,b, c,d;
printf("请输入4个整数:");
scanf("%d% d% d% d", &a, &b, &c, &d);
printf("原始顺序:%d,%d,%d,%d/n",a,b,c,d);
fun(&a,&b,&c,&d);
printf("处理后:%d,%d,%d,%d/n”,a,b,c,d);
NONO();
}
void NONO()
{/*本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。*/
FILE *fp,*wf;
int i,a,b, C,d;
fp=fopen("in.dat","r");
wf=fopen ("out.dat","w");
for (i=0; i<5; 1++ )
{fscanf(fp,"%d %d %d%d",&a,
&b,&c,&d);
fun(&a,&b,&c,&d);
fprintf (wf,"a=%d,d=%d/n",a,d);
}
fclose( fp);
fclose (wf);}
问答题编写一个函数,从mum个字符串中找出最长的一个字符串,并通过形参指针max传回该串地址(主函数中用★★★★作为结束输入的标志,函数fun中给出的语句仅供参考)。
注意:部分源程序存在文件PROG1.C中。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入编写的若干语句。
给定源程序如下。
#include<stdio.h>
#include<string.h>
void fun(char(*a)[81],int num,char**max)
{
/*以下代码仅供参考*/
int i,k=0,len,maxlen;/*k为a数组中最长串所在元素的下标,初始为0,maxlen为其串长*/
maxlen=strlen(a[k]);
for(i=1;i<num;i++)
{
/*以下完成查找最长串*/
}
*max=a[k];
}
main()
{
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;
fun(ss,n,
printf("/nmax=%s/n",ps);
}
问答题编写函数fun,w是一个大于10的无符号整数,若w是n(n≥2)位的整数,则函数求出w的后n-1位的数作为函数值返回。
例如,w值为5923,则函数返回923;若W值为923,则函数返回23。
注意:部分源程序给出如下。
请勿改动main函数和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
试题程序:
#include<stdlib.h>
#include<conio.h>
#include<stdio.h>
unsigned fun(unsigned w)
{
}
void main()
{
unsigned x;
system("CLS");
printf("Enter a unsigned integer number:");
scanf("%u",
printf("The original data is:%u/n",x);
if(x<10)
printf("Data error!");
else
printf("The result:%u/n",fun(x));
}
问答题请编一个函数float proc(double h),函数的功能是对变量h中的值保留2位小数,并对第3位进行四舍五入(规定h中的值为正数)。
例如,若h值为7.32596,则函数返回7.33;若h值为7.32496,则函数返回7.32。
注意:部分源程序给出如下。
请勿改动main()函数和其他函数中的任何内容,仅在函数proc()的花括号中填入所编写的若干语句。
试题程序:
#include<stdlib.h>
#include<stdio.h>
#include<conio.h>
float proc(float h)
{
}
void main()
{
float f;
system("CLS");
printf("Enter f:");
scanf("%f",
printf("The original data is:");
printf("%f/n/n", f);
printf("The result: %f/n", proc(f));
}
问答题填空题
请补充函数fun(),该函数的功能是:把一个整数转换成字符串,并倒序保存在字符数组str中。例如:当n=13572468时,str=“86427531”。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的横线上填入所编写的若干表达式或语句。
试题程序:
#include
#include
#define N 80
char str[N];
void fun(long int n)
{
int i=0;
while(【1】)
{
str[i]=【2】;
n/=10;
i++;
}
【3】;
}
main()
{
long int n=13572468;
clrscr();
printf("*** the origial data ***/n");
printf("n=%ld",n);
fun(n);
printf("/n%s",str);
}
