问答题请编写一个函数,用来删除字符串中的所有空格。例如,输入asd af aa z67,则输出为asdafaaz67。注意:部分源程序在文件PROG1.C中。请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。试题程序:1 #include<stdio.h>2 #include<ctype.h>3 #include<conio.h>4 #include<stdlib.h>5 void fun(char*str)6 {78 }9 main()10 {11 char str[81];12 char Nsg[]="Input a string.";13 int n;14 FILE*out;15 printf(Nsg);16 gets(str);17 puts(str);18 fun(str);19 printf("*** str:%s\n",str);20 /*****************/21 out=fopen("out.dat","w");22 fun(Nsg);23 fprintf(out,"%s",Hsg);24 fclose(out);25 /*****************/26 }
问答题请编写一个函数,用来删除字符串中的所有空格。
例如,输入abc de f gh,则输出为abcdefgh。
注意:部分源程序给出如下。
请勿改动main()函数和其他函数中的任何内容,仅在函数proc()的花括号中填入所编写的若干语句。
试题程序:
#include<stdio.h>
#include<ctype.h>
#include<conio.h>
#include<stdiib.h>
void proc(char*str)
{
}
void main()
{
char str[81];
system("CLS");
printf("Input a string: ");
gets(str);
puts(str);
proc(str);
printf("***str: %s/n", str);
}
问答题编程题
程序定义了N×N的二维数组,并在主函数中自动赋值。请编写函数fun(int a[ ][ N ],int n),该函数的功能是使数组左下半三角元素中的值加上n。
例如:若n的值为3,a数组中的值为
a=2 5 4
1 6 9
5 3 7
则返回主程序后a数组中的值应为
5 5 4
4 9 9
8 6 10
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
#include
#include
#include
#define N 5
fun(int a[ ][N], int n)
{
}
main()
{
int a[N][N],n, i,j;
clrscr();
printf("***** The array *****/n");
for(i=0; i=5);
printf("n=%4d/n",n);
fun(a, n);
printf("*****THE RESULT*****/n");
for(i=0; i
问答题请编写一个函数proc(),它的功能是:找出一维数组元素中最大的值和它所在的下标,最大值和它所在的下标通过形参传同。数组元素中的值已在主函数中赋予。
主函数中arr是数组名,n是arr中的数据个数,max存放最大值,index存放最大值所在元素的下标。
注意:部分源程序给出如下。
请勿改动main()函数和其他函数中的任何内容,仅在函数proc()的花括号中填入所编写的若干语句。
试题程序:
#include<time.h>
#include<stdlib.h>
#include<stdio.h>
void proc(int arr[],int n,int*max,int*d)
{
}
void main()
int i,arr[20],max,index,n=10;
srand((unsigned)time(NULL));
for(i=0;i<=n;i++)
{
arr[i]=rand()%50;
printf("%4d",arr[i]);
//输出一个随机数组
}
printf("/n");
proc(arr,n,
printf("Max=%5d,Index=%4d/n",max,index);
}
问答题请编写函数fun,其功能是:计算并输出下列多项式的值:例如,在主函数中从键盘给n输入15,则输出为:s=2.718282。注意:要求n的值大于1但不大于100。部分源程序在文件PROG1.C中。请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。#inolude<stdio.h>doublefun(intn){}main(){intn;doubles;printf("Inputn:");scanf("%d",s=fun(n);printf("s=%f/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<10;i++){fscanf(rf,"%d",s=fun(n);fprintf(wf,"%lf/n",s);}fclose(rf);fclose(wf);}
问答题请编写函数fun,其功能是分别统计形参t所指二维数组中字母A和C的个数。注意:部分源程序存在PROG1.C中,请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语匈.试题程序:#include<stdio.h>#include<stdlib.h>#define M 14 void NONO():void fun(char(*t)[M],int*a,int*c)}void get(char(*s)[M]){int i,j; for(i=0;i<M;j++) { for(j=0;j<M;j++) { s[i][j]=65+rand()%12;printf(“%c”,s[i 3[j]);} printf(“\n”); }}main(){char a[M][M]; int x,y; get(a); fun(a,&x,&y); printf(“A=%d C=%d\n”,x,y); NONO();}void NONO(){/*本函数用于打开文件,输人数据,调用函数,输出数据,关闭文件。*/ FILE*rp,*wf: int i,j,x,y: char a[M][M]; fp=fopen(“c:\test\in.dat”,“r”); wf=fopen(“c:\test\out.dat”,“W”); for(i=0;i<M;i++) {for(j=0;j<M;j++) {fscanf(rp,“%c”,&a[i][j]);} } fun(a,&x,&y); fprintf(wf,“A=%d\n”,x); fprintf(wf,“C=%d\n”,y); fclose(fp); fclose(wf);
问答题请编写函数void fun(int x,int PP[],int*n),它的功能是:求出能整除x且不是偶数的各整数,并按从小到大的顺序放在pp所指的数组中,这些除数的个数通过形参n返回。 例如,若x中的值为30,则有4个数符合要求,它们是1、3、5、15。 注意:请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。 试题程序:#include<conio.h>#include<stdio.h>#include<stdlib.h>void fun(int X,int PP[],int*n){}void main(){ FILE*wf; int x,aa[1000],n,i; system(“CLS”); printf(“\nPlease enter an integer number:\n”) ; scanf(“%d”,&x); fun(x,aa,&n); for(i=0;i<n;i++) prinff(“%d”,aa[i]);prinff(“\n”);/*****************/ wf=fopen(“out.dat”,“w”);fun(30,aa,&n);for(i=0;i<n;i++) fprintf(wf,“%d”,88.[i]); fclose(wf);/*****************/}
问答题给定程序中函数fun的功能是:将一个由八进制数字字符组成的字符串转换为与其值相等的十进制整数。规定输入的字符串最多只能包含5位八进制数字字符。 例如,若输入:77777,则输出将是:32767。 请改正程序中的错误,使它能得到正确结果。 [注意] 不要改动main函数,不得增行或删行,也不得更改程序的结构。 [试题源程序] #include<stdio.h> #include<string.h> #include<stdlib.h> 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; int 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]<'0'||s[i]>'7') printf("Error: %c not is ocatal digits!/n/n", s[i]); exit(0); printf("The original string:"); puts(s); n=fun(s); printf("/n%s iS convered to integer number: %d/n/n", s, n);
问答题下列给定程序中,函数proc()的作用是:将字符串str中的大写字母都改为对应的小写字母,其他字符不变。例如,若输入“abD,dFAD”,则输出“abd,dfad”。
请修改函数proc()中的错误,使它能得出正确的结果。
注意:不要改动main()函数,不得增行或删行,也不得更改程序的结构。
试题程序:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<conio.h>
char*proc(char str[])
{
int I;
for(I=0; str[I]; I++)
//****found****
if(("A"<=str[I]||(str[I]<="Z"))
str[I]+=32; }
return(str);
}
void main()
{
char str[81];
system("CLS");
printf("/nPlease enter a string: ");
gets(str);
printf("/nThe result string is: /n%s/n", proc(str));
}
问答题下列给定程序中,已建立一个带头结点的单向链表,链表中的各结点按结点数据域中的数据递增有序链接。函数fun的功能是:把形参x的值放入一个新结点并插入链表中,使插入后各结点数据域中的数据仍保持递增有序。 请在下画线处填入正确的内容并将下画线删除,使程序得出正确的结果。 注意:部分源程序给出如下。 不得增行或删行,也不得更改程序的结构! 试题程序: #include <stdio.h> #include <stdlib .h > #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 && x >p->data) /********** found********** / q= (2) ; 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; 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 x; int a[N]=11, 12, 15, 18, 19, 22, 25, 29; head=creatlist (a); printf ("/nThe list before inser- ting: /n"); outlist (head); printf("/nEnter a number : "); scanf ("% d", fun (head, x); printf (" /nThe list after inser- ting: /n"); outlist (head);
问答题编写函数fun,其功能是:将ss所指字符串中所有奇数位上的字母转换为大写(若该位置上不是字母,则不转换)。
例如,若输入“abc4EFg”,则应输出“aBc4EFg”。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任伺内容,仅在函数fun的花括号中填入你编写的若干语句。
试题程序:
#include<conio.h>
#include<stdio.h>
#include<string.h>
void fun(char*ss)
{
}
void main(void)
{
char tt[51];
printf("/nPlease enter an character string within 50 characters:/n");
gets(tt);
printf("/n/nAfter changing,the string/n%s", tt);
fun(tt);
printf("/nbecomes/n %s", tt);
}
问答题编写函数fun,其功能是:将S所指字符串中ASCII码值为奇数的字符删除,剩余字符形成的新串放在t所指数组中。
例如,若s所指字符串中的内容为“ABCDEFG12345”,其中字符A的ASCII码值为奇数,字符1的ASCII码值也为奇数,都应当删除,其他依次类推。最后t所指的数组中的内容应是“BDF24”。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
试题程序:
#include<conio.h>
#include<stdio.h>
#include<string.h>
void fun(char *s,char t[])
{
}
main()
{
char s[100],t[100],Msg[]="Please enter string s:";
printf(Msg);
scanf("%s",s);
fun(s,c);
printf("/nThe resuit is:%s/n",t);
}
问答题给定程序MODI1.C中fun函数的功能是:求出以下分数序列的前n项之和。和值通过函数值返回main函数。例如,若n=5,则应输出:8.391667。请改正程序中的错误,使它能得出正确的结果。注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!#include<stdio.h>/*************found*************/fun(intn){inta=2,b=1,c,k;doubles=0.0;for(k=1;k<=n;k++)(s=s+1.0*a/b;/*************found*************/c=a,a+=b;b+=c;}return(s);}main(){intn=5;printf("/nThevalueoffunctionis:%1f/n",fun(n));}
问答题函数fun的功能是:把形参a所指数组中的偶数按原顺序依次存放到a[0]、a[1]、a[2]、……中,把奇数从数组中删除,偶数个数通过函数值返回。例如:
若a所指数组中的数据最初排列为:9、1、4、2、3、6、5、8、7,删除奇数后a所指数组中的数据为:4、2、6、8,返回值为4。
请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。
注意:源程序存放在
下的BLANK1.C中。
不得增行或删行,也不得更改程序的结构!
#include<Stdio.h>
#define N 9
int fun(int a[], int n)
{int i, j;
j=0;
for(i=0; i<n; i++)
/**********found**********/
if(______==0){
/**********found**********/
______=a[i]; j++;
}
/**********found**********/
return______;
}
main()
{int b[N]=(9,1,4,2,3,6,5,8,7), i, n;
printf("/nThe original data:/n");
for(i=0; i<N; i++) printf("%4d", b[i]);
printf("/n");
n=fun(b, N);
printf("/nThe number of even:%d/n", n);
printf("/nThe even:/n");
for(i=0; i<n; i++)printf("%4d", b[i]);
printf("/n");
}
问答题请编写函数fun,该函数的功能是:求出二维数组周边元素之和,作为函数值返回。二维数组中的值在主函数中赋予。
例如,若二维数组中的值为:
1 3 5 7 9
2 9 9 9 4
6 9 9 9 8
1 3 5 7 0
则函数值为61。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
试题程序:
#include<stdlib.h>
#include<conio.h>
#include<stdio.h>
#define M 4
#define N 5
int fun(int a[M][N])
{
}
void main()
{
int aa[M][N]={{1,3,5,7,9}, {2,9,9,9,4}, {6,9,9,9,8}, {1,3,5,7,0}};
int i, j, y;
system("CLS");
printf("The original data is:/n");
for(i=0; i<M; i++)
{
for(j=0; j<N; j++)
printf("%6d", aa[i][j]);
printf("/n");
}
y=fun(aa);
printf("/nThe sun:%d/n", y);
printf("/n");
}
问答题编写一个函数,该函数可以统计一个长度为2的字符串在另一个字符串中出现的次数。例如,假定输入的字符串为abcdefabcdeabceabcdef,子字符串为cd,则应当输出3。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数proc的花括号中填入所编写的若干语句。
试题程序:
#include<stdlib.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
int proc(char*str,char*substr)
{
}
void main()
{
char str[81],substr[3];
int n;
system("CLS");
printf("输入主字符串:");
gets(str);
printf("输入子字符串:");
gets(substr);
puts(str);
puts(substr);
n=proc(str,substr);
printf("n=%d/n",n);
}
问答题请编写一个函数int fun(int*s,int t,int*k),用来求出数组的最大元素在数组中的下标并存放在k所指向的存储单元中。例如,输入如下整数:876 675 896 101 301 401 980 431 451 777则输出结果为6,980。注意:部分源程序在文件PROG1.C中。请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。试题程序:#include<conio.h>#include<stdio.h>#include<stdlib.h>int fun(int *s,int t,int*k){}void main(){ FILE*wf; int a[10]={876,675,896,101,301,401,980,431,451,777),k; system("CLS"); fun(a,10,&k); printf("%d,%d\n",k,a[k]); /******************/ wf=fopen("out.dat","W"); fprintf(wf,"%d,%d",k,a[k]); fclose(wf); /******************/}
问答题程序通过定义学生结构体变量,存储学生的学号、姓名和三门课的成绩。函数fun的功能是:将形参a中的数据进行修改,把修改后的数据作为函数值返回主函数进行输出。
例如,若传给形参a的数据中学号、姓名和三门课的成绩依次是:10001、“ZhangSan”、95、80、88,修改后的数据应为:10002、“LiSi”、96、81、89。
请在程序的下画线处填入正确的内容并将下画线删除,使程序得出正确的结果。
注意:部分源程序给出如下。
不得增行或删行,也不得更改程序的结构!
试题程序:
#include < stdio.h >
#include < string.h >
struct student{
long sno;
char name[10];
float score[3];
};
/*********found*********/
【1】
fun(struct student a)
{ int i;
a.silo=1 00 02;
/*********found*********/
strcpy(
【2】
,"Lisi");
/*********found*********/
for(i=0;i < 3;i++)
【3】
+=1;
return a;
}
main()
{ struct student s={10001,"
ZhangSan",95,80,8 8),t;
int i;
printf("/n/nThe originaldata:/n");
printf("/nNo:%ld Name:%s/n Scores:",s.sno,s.name);
for(i=0 j i < 3; i++)
printf("%6.2f",s.score[i]);
printf("/n");
t=fun(s);
printf("/nThe data after modified:/n");
printf("/nNo:%ld Name:%s/n Scores:",t.sno,t.name);
for(i=0;i < 3;i++)
printf("%6.2f",t.score[i]);
printf("/n");
}
问答题已知学生的记录由学号和学习成绩构成,N名学生的数据已存入a结构体数组中。请编写函数fun,该函数的功能是:找出成绩最低的学生记录,通过形参返回主函数(规定只有一个最低分)。已给出函数的首部,请完成该函数。注意:部分源程序在文件PROG1.C中。请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。试题程序:1 #include<stdio.h>2 #include<string.h>3 #include<conio.h>4 #inclucle<stdlib.h>5 #define N 106 typedef struct ss7 {char num[10];8 int s;9 }STU;10 fun(STU a[],STU*S)11 {1213 }14 void main()15 {16 FILE*wf;17 STU a[N]={("A01",81},{"A02",89),{"A03",66},{"A04",87),{"A05",77),{"A06",90},{"A07",79),{"A08",61),{"A09",80},{"A10",71}},m;18 int i;19 system("CLS");20 printf("*****The original data*****\n");21 for(i=0;i<N;i++)22 printf("No=%S Mark=%d\n",a [i].num,a[i].s);23 fun(a,&m);24 printf("****THE RESULT****\n");25 printf(“The lowest:%S,%d\n",m.num,m.s);26 /******************/27 wf=fopen("out.dat","W");28 fprintf(wf,"%s,%d",m.num,m.s);29 fclose(wf);30 /******************/}
问答题下列程序定义了N×N的二维数组,并在主函数中自动赋值。请编写函数fun(int a[][N]),该函数的功能是:将数组左下半三角元素中的值全部置0。例如a数组中的值为: 1 9 7 2 3 8 4 5 6 则返回主程序后a数组中的值应为: 0 9 7 0 0 8 0 0 0 注意:请勿改动main函数和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。试题程序:#include<conio.h>#include<stdio.h>#include<stdlib.h>}}define N 5void fun(int a[][N]){}void main(){FILE*wf; int a[N][N],i,j; int b[N][N]=t 1,9,7,2,4,2,3,8,1,2,4,5,6,7,5,4,0,6,8,0,2,7,1,6,4}; system(“CLS”); prinff(“******The array******\n”); for(i=0;i<N;i++)/*产生一个随机的5*5矩阵*/ { for(j=0;j<N;j++) { a[i][j]=rand()%10; printf(“%4d”,a[i][j]); } prinff(“\n”); } fun(a); printf(“THE RESULT\n”); for(i=0;i<N;i++) { for(j=0;j<N;j++) printf(“%4d”,a[i][j]); prinff(“\n”); }/************/wf=fopen(“out.dat”,“w”);fun(b);for(i=0;i<N;i++){ for(j=0;j<N;j++) fprinff(wf,”%4d”,b[i][j]); fprintf(wf,“\n”); } felose(wf);/************/}
