问答题请编写函数fun,函数的功能是求出二维数组周边元素之和,作为函数值返回。二维数组中的值在主函数中赋予。
例如:二维数组中的值为
1 3 5 7 9
2 9 9 9 4
6 9 9 9 8
1 3 5 7 0
则函数值为61。
注意:部分源程序存在文件PROG1.C中。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入编写的若干语句。
给定源程序如下。
#include<stdio.h>
#define M 4
#define N 5
int fun(int a[M][N])
{
}
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;
printf("The original datais:/n");
for(i=0;i<M;i++)
{ for(j=0;j<N;j++)printf("%6d",aa[i][j]);
printf("/n");
}
Y=fun(an);
printf("/nThe sum:%d/n",y);
printf("/n");
}
问答题下列给定程序是建立一个带头结点的单向链表,并用随机函数为各结点赋值。函数fun()的功能是:将单向链表结点(不包括头结点)数据域为偶数的值累加起来,并作为函数值返回。 其累加和通过函数值返回main()函数。例如,若n=5,则应输出8.391667。 请改正程序中的错误,使它能得到正确结果。 [注意] 不要改动main函数,不得增行或删行,也不得更改程序的结构。 [试题源程序] #include<stdio.h> #include<stdiib.h> typedef struct aa int data; struct aa *next; NODE; int fun(NODE *h) int sum=0; NODE *P; /**********found**********/ p=h; while(P->next) if(p->data%2==0) sum+=p->data; /**********found**********/ p=h->next; return sum; NODE *creatlink(int n) NODE *h, *p, *s, *q; int i, x; h=p=(NODE *)malloc(si zeof(NODE)); for(i=1; i<=n; i++) s=(NODE *)malloc(sizeof(NODE)); s->data=rand()%16; s->next=p->next; p->next=s; p=p->next; p->next=NULL; return h; outlink(NODE *h, FILE *Pf) NODE *p; p=h->next; fprintf(Pf, "/n/nTHE LIST:/n/n HEAD"); while(P) fprintf(Pf, "->%d", p->data); p=p->next; fprintf(pf, "/n"); outresult(int s, FILE *pf) fprintf(Pf, "/nThe sum of even numbers : %d/n", s); main() NODE *head; int even; head=creatlink(12); head->data=9000; outlink(head, stdout); even=fun(head); printf("/nThe result :/n"); outresult(even, stdout);
问答题请编写函数fun,对长度为7个字符的字符串,除首、尾字符外,将其余5个字符按ASCH码降序排列。
例如,原来的字符串为:CEAedca,排序后输出为:CedcEAa。
注意:部分源程序在文件PROG1.C中。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
#include
#include
#include
void fun(char *s,int num)
{
}
NONO()
{
/*请在此函数内打开文件,输入测试数据,
调用fun函数,输出数据,关闭文件。*/
char s[10] ;
FILE *rf, *wf ;
int i = 0 ;
rf = fopen("in.dat","r") ;
wf = fopen("out.dat","w");
while(i < 10) {
fgets(s,10,rf);
s[7] =0 ;
fun(s,7) ;
fprintf(wf, "%s/n", s);
i++ ;
}
fclose(rf);
fclose(wf);
}
main ()
{
char s [10];
printf ("输入7个字符的字符串: ") ;
gets (s);
fun(s,7);
printf("/n%s",s);
NONO();
}
问答题编写函数fun,其功能是:将两个两位数的正整数a、b合并成一个整数放在c中。合并的方式是:将a数的十位和个位数依次放在c数的个位和百位上,b数的十位和个位数依次放在c数的十位和千位上。
例如,当a=45,b=12时,调用该函数后c=2514。
注意:部分源程序给出如下。
请勿改动主函数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:%ld/n", c);
}
问答题下列给定程序中,函数fun的功能是:将一个由八进制数字字符组成的字符串转换成十进制整数。规定输入的字符串最多只能包含S位八进制数字字符。
例如,若输入77777,则输出32767。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!
试题程序:
#include<stdio.h>
#include<stdlib.h>
#include<string.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(octal 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 octal digits!/n/n",s[i]);
exit(0);
}
printf("The originl string:");
puts(s);
n=fun(s);
printf("/n%s is convered to intege number:%d/n/n",s,n);
}
问答题在主函数中从键盘输入若干个数放入数组中,用0结束输入并放在最后一个元素中。下列给定程序中,函数proc()的功能是计算数组元素中值为负数的平均值(不包括0)。
例如,数组中元素的值为78、-65、-15、35、-45、0,则程序的运行结果为-41.666667。
请修改程序中的错误,使它能得到正确结果。
注意:不要改动main()函数,不得增行或删行,也不得更改程序的结构。
试题程序:
#include<stdlib.h>
#include<conio.h>
#include<stdio.h>
double proc(int x[])
{
double sum=0.0;
int c=0,i=0;
//****found****
while(x[i]==0)
{
if(x[i]<0)
{
sum=sum+x[i];
c++;
}
i++;
}
//****found****
sum=sum/c;
return sum;
}
void main()
{
int x[1000];
int i=0;
system("CLS");
printf("/nPlease enter somc data(end with 0): ");
do
{
scanf("%d", 8 x[i]);
}
while(x[i++]!=0);
printf("%f/n", proc(x));
}
问答题给定程序中,函数fun的功能是将带头节点的单向链表结点数据域中的数据从小到大排序。即若原链表结点数据域从头至尾的数据为:10、4、2、8、6,排序后链表结点数据域从头至尾的数据为: 2、4、6、8、 10。
请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。
注意:源程序存放在考生文件夹下的BLANK1.C中。
不得增行或删行,也不得更改程序的结构!
#include
#include
#define N 6
typedef struct node {
int data;
struct node *next;
} NODE;
void fun(NODE *h)
{NODE *p, *q; int t;
/*********** found********** /
p=【1】;
while (p) {
/********** found**********/
q = [2] ;
while (q)
{ /********** found**********/
if (p->data 【3】 q->data)
{ t = p->data; p->data = q-> data;
q->data = t;}
q = q->next;
}
p = p->next;
}
}
NODE *creatlist(int a[])
{NODE *h,*p,*q; int i;
h = (NODE *)malloc(sizeof(NODE));
h->next = NULL;
for(i=0; idata=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("/nHead ");
do
{printf("->%d",p->data);
p=p->next;}
while(p!=NULL);
printf("->End/n");
}
}
main ()
{NODE *head;
int a[N]= {0, 10, 4, 2, 8, 6 };
head=creatlist(a);
printf("/nThe original list:/n");
outlist(head);
fun(head);
printf("/nThe list after sorting:
/n");
outlist(head);
}
问答题请编写函数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<conio.h> #include<stdio.h> #define M 4 #define N 5 int fun( int a [M][N]) 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; clrscr(); printf ("The original data is :/n "); for(i=0; i<N;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");
问答题编写函数fun,其功能是:求ss所指字符串中指定字符的个数,并返回此值。
例如,若输入字符串123412132,输入字符为1,则输出3。
注意:请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
#include<stdio.h>
#include<string.h>
#define M 81
int fun(char*ss,char c)
{
}
main()
{char a[M],ch;
void NONO();
printf("/nPlease enter a string:");gets(a);
printf("/nPlease enter a char:");ch=getchar();
printf("/nThe number of the char is:%d/n",fun(a,ch));
NONO();
}
void NONO()
{/*本函数用于打开文件,输入测试数据,调用fun函数,输出数据,关闭文件。*/
int i;
FILE *rf,*wf;
char a[M],b[M],ch;
rf=fopen("in.dat","r");
wf=fopen("out.dat","w");
for(i=0;i<10;i++)
{
fscanf(rf,"%s",a);
fscanf(rf,"%s",b);
ch=*b;
fprintf(wf,"%c=%d/n",ch,fun(a,ch));
}
fclose(rf);
fclose(wf);
}
问答题函数fun的功能是将s所指字符串中ASCII值为奇数的字符删除,串中剩余字符形成一个新串放在t所指的数组中。
例如,若s所指字符串中的内容为“ABCDEFG12345”,其中字符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);
}
问答题下列给定的程序中,函数fun的功能是:计算并输出k以内最大的10个能被13或17整除的自然数之和。k的值由主函数传入,若k的值为500,则函数的值为4622。请改正程序中的错误,使它能得出正确的结果。注意:部分源程序在文件MODI1.C中,不要改动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));}
问答题规定输入的字符串中只包含字母和*号。请编写函数fun,其功能是:使字符串中尾部的*号不多于n个,若多于n个,则删除多余的*号;若少于或等于n个,则不做任何操作,字符串中间和前面的*号不删除。 例如,字符串中的内容为“****A*BC*DEF*G*******”,若n的值为4,删除后,字符串中的内容应为“****A*BC*DEF*G****”;若n的值为7,则字符串中的内容仍为“****A*BC*DEF*G*******”。n的值在主函数中输入。编写函数时,不得使用C语言提供的字符串函数。 注意:部分源程序给出如下。 请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。 试题程序: #include<stdio.h> void fun(char*a,int n) main() char s[81];int n; printf("Enter a string:/n"); gets(s); printf("Enter n:"); scanf("%d",&n); fun(s,n); printf("The string after deleted:/n"); puts(s);
问答题填空题
请补充函数fun(),该函数的功能是:按‘0’到‘9’统计一个字符串中的奇数数字字符各自出现的次数,结果保存在数组num中。注意:不能使用字符串库函数。
例如:输入“x=112385713.456+0.909*bc”,结果为:1=3,3=2,5=2,7=1,9=2。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun()的横线上填入所编写的若干表达式或语句。
试题程序:
#include
#define N 1000
void fun(char *tt,int num[])
{
int i,j;
int bb[10];
char *p=tt;
for(i=0;i=''0''
p++;
}
for(i=1,j=0;i<10;i=i+2,j++)
【3】;
}
main()
{
char str[N];
int num[10],k;
clrscr();
printf("/nPlease enter a char string:");
gets(str);
printf("/n**The original string**/n");
puts(str);
fun(str,num);
printf("/n**The number of letter**/n");
for(k=0;k<5;k++)
{
printf("/n");
printf("%d=%d",2*k+1,num[k]);
}
printf("/n");
return;
}
问答题函数fun的功能是:将s所指字符串中下标为偶数同时ASCII值为奇数的字符删除,s所指串中剩余的字符形成的新串放在t所指的数组中。 注意:部分源程序给出如下。 请勿改动mam函数和其他函数中的任何内容,仅在函数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);
问答题下列给定程序中,fun函数功能是:将n个无序整数从小到大排序。请改正程序中的错误,使它能得出正确的结果。 注意:不得增行或删行,也不得更改程序的结构! 试题程序: #include<stdio.h> #include<stdlib.h> fun(int n,int *a) { int i,j,p,t; for(j=0;j<n一1;j++) { p=j; /******found******/ for(i=j+1;i<n一1;i++) if(a[p]>a[i]) /******found******/ t=i: if(p!=j) { t=a[i];a[j]=a[p];a[p]=t; } } } putarr(int n,int *z) { int i; for(i=1;i<=n;i++,z++) { printf("%4d",*z); if(!(i%10))printf("\n"); } printf("\n"); } main() { int aa [20]={9,3,0,4,1,2,5,6,8,10,7},n=11; printf( "Before sorting %d numbers:\n",n); putarr(n,aa); fun(n,aa); printf( "After sorting %d numbers:\n",n); putarr(n,aa); }
问答题某学生的记录由学号、8门课成绩和平均分组成,学号和8门课的成绩已在主函数中给出。请编写proc()函数,它的功能是:求出该学生的平均分放在记录的avc成员中。请自己定义正确的形参。 例如,若学生的成绩是65.5,75,88,90,90.5,66,64.5,89.5,则他的平均分应当是78.625。 注意:部分源程序已给出。 请勿改动主函数main和其他函数中的任何内容,仅在函数proc的花括号中填入所编写的若干语句。 试题程序: #include<stdio.h> #define M 8 typedef struct char num[10]; double s[M]; double ave; STREC; void proc(STREC *p) void main() STREC stu="GA005", 65.5, 75, 88, 90, 90.5, 66, 64.5, 89.5; int i; proc ( printf ("The %s's student data: /n", stu. num); //输出学号 for(i=0; i<M; i++) printf ("%4.1f/n", stu.s[i]); //输出各科成绩 printf("nave=%7.3f/n", stu.ave); //输出平均分
问答题请编写函数fun,其功能是:找出一维整型数组元素中最大的值及其所在的下标,并通过形参传回。数组元素中的值已在主函数中赋予。主函数中x是数组名,11是x中的数据个数,max存放最大值,index存放最大值所在元素的下标。注意:部分源程序给出如下。请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。试题程序:#inclucle<time.h>#include<stdlib.h>#include<stdio.h>void fun(int a[ ],int n,int*max,int*d){}void main(){ int i,x[20],max,index,n=10; srand((unsigned)time(NULL)); for(i=0;i<=n ;i++) { x[i]=rand()%50 ; printf("%4d",x[i]); /*输出一个随机数组*/ } printf("\n"); fun(x,n,&max,&index); printf("Nax=%5d,Index=%4d\n",max,index);}
问答题请编写一个函数fun,它的功能是:求出一个2×M整型二维数组中最大元素的值,并将此值返回调用函数。
注意:部分源程序存在文件PROG1.C中。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入编写的若干语句。
给定源程序如下。
#include<stdio.h>
#define M 4
int fun(int a[][M])
{
}
main()
{ int arr[2][M]={5,8,3,45,76,-4,12,82};
printf("max=%d/n",fun(arr));
}
问答题请编写函数fun(),该函数的功能是:将M行N列的二维数组中的字符数据,按列的顺序依次放到一个字符串中。
例如,若二维数组中的数据为:
W WWW
S S S S
H H H H
则字符串中的内容应是WSHWSHWSHWSH。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
#include<stdio.h>
#define M 3
#define N 4
void fun(char (*s)[N],char *b)
{
}
main()
{
char a[100],w[M][N]={{ "W", "W", "W", "W"},
{"S", "S", "S", "S"},{"H", "H", "H", "H"}};
int i,j;
printf("The matrix:/n");
for(i=0;i<M;i++)
{ for(j=0;j<N;j++)
printf("%3c",w[i][j]);
printf("/n");
}
fun(w,a);
printf("The A string:In");
puts(a);
printf("/n/n");
}
问答题请编写函数fun(),该函数的功能是:计算n门课程的平均分,计算结果作为函数值返回。 例如x有5门课程的成绩是90.5,72,80,61.5,55,则函数的值为71.80。 注意:部分源程序给出如下. 请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。 试题程序: #include <stdio.h> float fun (float *a, int n) main () float score[30]=(90.5,72,80,61.5,55, aver; aver=fun(score, 5); printf("/nAverage score is: %5.2f /n",aver);
