问答题给定程序中函数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);/************/}
问答题给定程序中,函数proc()的功能是:使数组中的元素的值增加10倍。
修改其中的错误,使它能得出正确的结果。
注意:不要改动main()函数,不得增行或删行,也不得更改程序的结构。
试题程序:
#include<sldio.h>
#include<conio.h>
int m[10];
void proc(void)
{
int j;
printf("In subfunc after calling/n");
for(j=0; j<10; j++)
{
//****found****
printf("%3d", m[j]*10);
}
}
void main()
{
int i;
printf("In main before calling/n");
for(i=0; i<10; i++)
{
m[i]=i;
printf("%3d", m[i]);
}
proc();
printf("/nIn main after calling/n");
for(i=0; i<10; i++)
printf("%3d", m[i]);
getch();
}
问答题下列给定程序中,函数fun的功能是:实现两个整数的交换。例如,给a和b分别输入60和65,输出为:a=65 b=60。
请改正程序中的错误,使它能得出正确的结果。
注意:
不要改动main函数,不得增行或删行,也不得更改程序的结构。
[试题源程序]
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
/***********found**********/
void fun(int a,b)
{
int t;
/***********found**********/
t=b;b=a,a=t;
}
void main()
{
int a,b;
system("CLS");
printf("Enter a,b:");
scanf("%d%d",
fun(
printf("a=%d b=%d/n",a,b);
}
问答题请编写一个函数,函数的功能是删除字符串中的所有空格。
例如, 主函数中输入"asd af aa z67", 则输出为 "asdafaaz67"。
注意:部分源程序在文件PROG1.C中。
请勿改动主函数main和其它函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
给定源程序:
#include
#include
int fun(char *str)
{
}
main()
{
char str[81];
int n;
printf("Input a string:") ;
gets(str);
puts(str);
fun(str);
printf("*** str: %s\n",str);
NONO();
}
问答题下列给定程序中,函数fun的功能是:输出M×M整数方阵,然后求两条对角线上元素之和,并作为函数值返回。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!
试题程序:
#include<stdlib.h>
#include<conio.h>
#include<stdio.h>
#define M 5
/********found********/
int fun(int n,int xx[][])
{
int i,j,sum=0;
printf("/nThe%d x%d matrix:/n",M,M);
for(i=0;i<M;i++)
{
for(j=0;j<M;j++)
/********found********/
printf("%f",xx[i][j]);
printf("/n");
}
for(i=0;i<n;i++)
sum+=xx[i][i]+xx[i][n-i-1];
return(sum);
}
void main()
{
int aa[M][M]={{1,2,3,4,5},{4,3,2,1,0},{6,7,8,9,0},{9,8,7,6,5},{3,4,5,6,7}};
system("CLS");
printf("/nThe sum of all elements on 2 diagnals is%d",fun(M,aa));
}
问答题请编写函数fun, 函数的功能是: 删去一维数组中所有相同的数, 使之只剩一个。数组中的数已按由小到大的顺序排列,函数返回删除后数组中数据的个数。
例如, 一维数组中的数据是: 2 2 2 3 4 4 5 6 6 6 6 7 7 8 9 9 10 10 10。
删除后,数组中的内容应该是: 2 3 4 5 6 7 8 9 10。
注意:部分源程序在文件PROG1.C中。
请勿改动主函数main和其它函数中的任何内容, 仅在函数fun的花括号中填入你编写的若干语句。
给定源程序:
#include
#define N 80
int fun(int a[], int n)
{
}
main()
{ int a[N]={2,2,2,3,4,4,5,6,6,6,6,7,7,8,9,9,10,10,10,10},i,n=20;
printf("The original data :/n");
for(i=0; in=fun(a,n);
printf("/n/nThe data after deleted :/n");
for(i=0;i}
问答题给定程序中已建立一个带有头结点的单向链表,链表中的各结点按数据域递增有序链接。函数fun的功能是:删除链表中数据域值相同的结点,使之只保留一个。
请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。
注意:源程序存放在
下的BLANK1.C中。
不得增行或删行,也不得更改程序的结构!
#include<stdio.h>
#inolude<stdlib.h>
#define N 8
typedef struct list
{ int data;
struct list *next;
} SLIST;
void fun(SLIST *h)
{SLIST *p, *q;
p=h->next;
if(p!=NULL)
{ q=p->next;
while(q!=NULL)
{ if(p->data==q->data)
(p->next=q->next;
/**********found**********/
free(______);
/**********found**********/
q=p->______;
}
else
{p=q;
/**********found**********/
q=q->______;
}
}
}
}
STIST *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 a[N]={1,2,2,3,4,4,4,5);
head=creatlist(a);
printf("/nThe list before deleting:/n"); outlist(head);
fun(head);
printf("/nThe list after deleting:/n"); outlist(head);
}
问答题规定输入的字符串中只包含字母和*号。编写函数fun,其功能是:删除字符串中所有的*号。编写函数时,不得使用C语言提供的字符串函数。例如,字符串中的内容为“****A*BC*DEF*G*******”,删除后,字符串中的内容应当是“ABCDEFG”。注意:部分源程序给出如下。请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。试题程序:#include<conio.h>#include<stdio.h>void fun(char*a){}void main(){ char s[81]; print;f("Enter a string:\n"); gets(s); fun(s); printf("The string after deleted:\n"); puts(s);}
