问答题编写函数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",&a,&b); fun(a,b,&c); printf("The result is:%idkn",c);}
问答题给定程序中,函数fun的功能是:计算形参x所指数组中N个数的平均值(规定所有数均为正数),作为函数值返回;并将大于平均值的数放在形参y所指数组中,在主函数中输出。
例如,有10个正数:46 30 32 40 6 17 45 15 48 26,平均值为:30.500000
主函数中输出:46 32 40 45 48
请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。
注意:源程序存放在
下的BLANK1.C中。
不得增行或删行,也不得更改程序的结构!
#include <stdlib.h>
#include <stdio.h>
#define N 10
double fun(double x[],double *y)
{ int i,j;double av;
/**********found**********/
av=______;
/**********found**********/
for(i=0;i<N;i++) av=av+______;
for(i=j=0;i<N;i++)
/**********found**********/
if(x[i]>av) y[______]=x[i];
y[j]=-1;
return av;
}
main()
{ int i;double x[N],y[N];
for(i=0;i<N;i++){x[i]=rand()%50;printf("%4.0f",x[i]);}
printf("/n");
printf("/nThe average is:%f/n",fun(x,y));
for(i=0;y[i]>=0;i++) printf("%5.1f",y[i]);
printf("/n");
}
问答题请编写函数proc(),该函数的功能是:将M行N列的二维数组中的字符数据,按列的顺序依次放到一个字符串中。例如,若二维数组中的数据为:
W W W
S S S
H H H
I I I
则字符串中的内容应是WSHIWSHIWSHI。
注意:部分源程序给出如下。
请勿改动main()函数和其他函数中的任何内容,仅在函数proc()的花括号中填入所编写的若干语句。
试题程序:
#include<stdio.h>
#define M 4
#define N 3
void proc(char(*s)[N],char*b)
{
}
void main()
{
char a[100], w[M][N]={{"W", "W", "W"}, {"S", "S", "S", }, {"H", "H", "H", }, {"I", "I", "I"}};
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");
}
proc(w, a);
printf("The A string:/n");
puts(a);
printf("/n/n");
}
问答题编写一个函数,从传入的M个字符中找出最长的一个字符串,并通过形参指针max传回该串地址(用****作为结束输入的标志)。
注意:部分源程序给出如下:
请勿改动main()函数和其他函数中的任何内容,仅在函数proc()的花括号中填入所编写的若干语句。
试题程序:
#include<stdio.h>
#include<string.h>
#include<conio.h>
char*proc(char(*a)[81], int num)
{
}
void main()
{
char ss[10][81], *max;
int n, i=0;
printf("输入若干个字符串:");
gets(ss[i]);
puts(ss[i]);
while(! stremp(ss[i], "****")==0)
{
i++;
gets(ss[i]);
puts(ss[i]);
}
n=i;
max=proc(ss, n);
printf("/nmax=%s/n", max);
}
问答题请编写函数fun,其功能是:计算并输出3~n之间所有素数的平方根之和。例如,若主函数从键盘给n输入100后,则输出为sum=148.874270。注意:n的值要大于2但不大于100。请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。试题程序:#include<stdio.h>#include<math.h>double fun(int n){}main(){ int n; double sum; FILE*out: printf(“Input n=”); searlf(“%d”,&n); SHm=fun(n); printf(“\nsum=%f\n”,sum);/********************/ out=fopen(“out.dat”,“W”); fprintf(out,“%f\n”,fun(180)); felose(out);/********************/}
问答题学生的记录由学号和成绩组成,N名学生的数据已在主函数中放入结构体数组s中,请编写函数fun,它的功能是:按分数的高低排列学生的记录,高分在前。 注意:部分源程序在文件PROG1.C中,请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。 文件PROG1.C的内容如下: #include<stdio.h> #define N 16 typedef struct char num[10]; int s; STREC; void fun(STREC a[]) void main( ) STREC s[N]="GA005",85,"GA003",76,"GA002",69,"GA004",85, "GA001",91,"GA007",72,"GA008",64,"GA006",87, "GA015",85,"GA013",91,"GA012",64,"GA014",92, "GA011",66,"GA017",65,"GA018",68,"GA016",72; int i: fun(s); printf("The data after sorted: /n"); for(i=0;i<N;i++) if(i%4==0)printf("/n"); printf("%s%4d",s[i].num,s[i].s): printf("/n");
问答题请编写函数fun(),它的功能是求Fibonacci数列中小于t的最大的一个数,结果由函数返回。其中Fibonacci数列F(n)的定义为
F(0)=0,F(1)=1
F(n)=F(n-1)+F(n-2)
例如:t=1000时,函数值为987。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
#include <conio.h>
#include <math.h>
#include <stdio.h>
int fun(int t)
{
}
main()
{
int n;
clrscr();
n=1000;
printf("n=%d, f=%d/n",n, fun(n));
}
问答题给定程序中,函数fun的功能是:将a所指3×5矩阵中第k列的元素左移到第0列,第k列以后的每列元素行依次左移,原来左边的各列依次绕到右边。
例如,有下列矩阵:
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
若k为2,程序执行结果为
3 4 5 1 2
3 4 5 1 2
3 4 5 1 2
请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。
注意:源程序存放在考生文件夹下的BLANK1.C中。不得增行或删行,也不得更改程序的结构!
给定源程序:
#include
#define M 3
#define N 5
void fun(int (*a)[N],int k)
{ int i,j,p,temp;
/**********found**********/
for(p=1; p<= __1__; p++)
for(i=0; i
{ temp=a[i][0];
/**********found**********/
for(j=0; j< __2__ ; j++) a[i][j]=a[i][j+1];
/**********found**********/
a[i][N-1]= __3__;
}
}
main( )
{ int x[M][N]={ {1,2,3,4,5},{1,2,3,4,5},{1,2,3,4,5} },i,j;
printf("The array before moving:/n/n");
for(i=0; i
{ for(j=0; jprintf("/n");
}
fun(x,2);
printf("The array after moving:/n/n");
for(i=0; i
{ for(j=0; jprintf("/n");
}
}
问答题已知学生的记录由学号和学习成绩构成,N名学生的数据已存入结构体数组a中。请编写函数fun,函数的功能是:找出成绩最高的学生记录,通过形参指针传回主函数(规定只有一个最高分)。已给出函数的首部,请完成该函数。
注意:部分源程序存在文件PROG1.C中。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
#include
#include
#define N 10
typedef struct ss
{ char hum[10]; int s;} STU;
fun(STU a[], STU *s)
{
}
main ()
{STU
a[N]={{"A01",81},{"A02",89},
{"A03",66},{"A04",87},{"A05",
77},{"A06",90},{"A07",79},{"A
08",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 top : %s , %d/n",
m.num, m.s);
NONO();
}
NONO()
{/*本函数用于打开文件,输入数据,
调用函数,输出数据,关闭文件。 */
FILE *rf, *wf ;
STU a[N], m ;
int i ;
rf = fopen("in.dat","r");
wf = fopen("out.dat","w");
for(i = 0 ; i < 10; i++)
fscanf(rf, "%s %d", a[i].num,
fun(a,
fprintf(wf,"The
top : %s, %d/n", m.num, m.s);
fclose(rf);
fclose(wf);
}
问答题编写函数fun,其功能是:删除一个字符串中指定下标的字符。其中,a指向原字符串,删除指定字符后的字符串存放在b所指的数组中,n放指定的下标。 注意:部分源程序给出如下。 请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。 试题程序: #include<stdio.h> #include<conio.h> #define LEN 20 void fun(char a[], char b[], int n) void main() char str1[LEN], str2[LEN]; int n; printf("Enter the string:/n"); gets(str1); printf("Enter the position of the string deleted:"); scanf("%d",&n); fun(str1, str2, n); printf("The new string is:%s/n", str2);
问答题给定程序中,函数fun的功能是:在形参ss所指字符串数组中,删除所有串长超过k的字符串,函数返回所剩字符串的个数。ss所指字符串数组中共有N个字符串,且串长小于M。 请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。 注意:源程序存放在考生文件夹下的BLANK1.C中。 不得增行或删行,也不得更改程序的结构!#include<stdio.h>#include<string.h>#define N 5#define M 10int fun(char(*ss)[M],int k){int i,j=0,len;/**********found**********/ for(i=0;i<【1】;i++){len=strlen(ss[i]);/**********found**********/if(len<=【2】)/**********found**********/strcpy(ss[j++],【3】);}return j;}main(){charx[N][M]={"Beijing","Shanghai","Tianjing","Nanjing","Wuhan"};int i,f;printf("\nThe originalstring\n\n");for(i=0;i<N;i++)puts(x[i]);printf("\n");f=fun(x,7);printf("The string witchlengthis less than or equal to 7:\n");for(i=0;i<f;i++)puts(x[i]);printf("\n");}
问答题给定程序中,函数fun的功能是:把形参s所指字符串中下标为奇数的字符右移到下一个奇数位置,最右边被移出字符串的字符绕回放到第一个奇数位置,下标为偶数的字符不动(注:字符串的长度大于等于2)。例如,形参s所指的字符串为:abcdefgh,执行结果为:ahcbedgf。
请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。
注意:源程序存放在考生文件夹下的BLANK1.C中。
不得增行或删行,也不得更改程序的结构!
#include
void fun (char *s)
{ int i,n. k; char c;
n=0;
for(i=0;s[i]!='/0';i++)n++;
/*********found**********/
if(n%2==0) k=n— ____1____ ;
else k=n—2;
c= ____2____ ;
for (i=k—2; 1>=1; i=i—2) s [i+2] =
s[i];
/*********found**********/
s[1]=____3____;
}
main ()
{ char s[80]="abcdefgh";
printf("/nThe original string
is : %s/n",s);
fun (s) ;
printf ("/nThe result is : %s/n",s) ;
}
问答题下列给定的程序中,proc()函数的功能是:将str所指字符串中每个单词的最后一个字母改成大写(这里的“单词”是指有空格隔开的字符串)。
例如,若输入:How do you do,则输出:HoW dOyoU dO。
请修改程序中的错误,使它能得出正确的结果。
注意:不要改动main()函数,不得增行或删行,也不得更改程序的结构。
试题程序:
#include<stdlib.h>
#include<string.h>
#include<conio.h>
#include<ctype.h>
#include<stdio.h>
void proc(char*str)
{
int k=0;
for(; *str; str++)
if(k)
{
//****found****
if(str=="")
{
k=0;
//****found****
*str=toupper(*(str-1));
}
}
else
k=1;
}
void main()
{ char chrstr[64];
int d;
system("CLS");
printf("/nPlease enter an English
sentence within 63 letters: ");
gets(chrstr);
d=strlen(chrstr);
chrstr[d]="";
chrstr[d+1]=0;
printf("/nBofore changing: /n%s", chrstr);
proc(chrstr);
printf("/nAfter changing: /n%s", chrstr);
}
问答题编写函数fun,其功能是:求ss所指字符串中指定字符的个数,并返回此值。
例如,若输入字符串“123412132”,输入字符为“1”,则输出3。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
试题程序:
#include<stdlib.h>
#include<conio.h>
#include<stdio.h>
#define M 81
int fun(char *ss,char c)
{
}
void main()
{
char a[M],ch;
system("CLS");
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));
}
问答题下列程序定义了N×N的二维数组,并在主函数中赋值。请编写函数fun,函数的功能是:求出数组周边元素的平均值并作为函数值返回给主函数中的s。例如,若a数组中的值为:
0 1 2 7 9
1 9 7 4 5
2 3 8 3 1
4 5 6 8 2
5 9 1 4 1
则返回主程序后s的值应为3.375。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#define N 5
double fun (int w[][N])
{
}
void main()
{
int a[N][N]={0,1,2,7,9,1,9,7,4,5,2,3,8,3,1,4,5,6,8,2,5,9,1,4,1};
int i,j;
double s;
system("CLS");
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:%1f/n",s);
}
问答题下列给定程序中函数fun的功能是:将tt所指字符串中的小写字母全部改为对应的大写字母,其他字符不变。
例如,若输入“Ab,cD”,则输出“AB,CD”。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!
试题程序:
#include<conio.h>
#include<stdio.h>
#inelude<string.h>
char *fun(char tt[])
{
int i;
for(i=0;tt[i];i++)
/********found********/
if((tt[i]>="a")||(tt[i]<="z"))
/********found********/
tt[i]+=32;
return(tt);
}
main()
{
char tt[81];
printf("/nPlease enter a string:");
gets(tt);
printf("/nThe result string is:/n%s",fun(tt));
}
问答题请编写函数fun,其功能是:将所有大于1小于整数m的非素数存入xx所指数组中,非素数的个数通过k传回。 例如,若输入:17,则应输出: 4 6 8 9 10 12 14 15 16。 注意:部分源程序在文件PROG1.C中。 请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。#include <stdio.h>void fun (int m, int *k, int xx [ ]){}main () {int m, n, zz[100];void NONO () ; printf("/nPlease enter an integer number between 10 and 100: ");scanf("%d", fun(n, printf("/n/nThere are %d non-prime numbers less than %d:", m, n);for(n =0; n < m; n++)printf("/n %4d", zz[n]);NONO();}void NONO(){/*请在此函数内打开文件,输入测试数据,调用fun函数,输出数据,关闭文件。*/int m, n, zz [100] ;FILE *rf, *wf ;rf = fopen("in.dat","r");wf = fopen("out.dat","w");fscanf(rf, "%d", fun (n, fprintf(wf, "%d/n%d/n"/ m, n) ; for(n = 0; n < m; n++) fprintf(wf, "%d/n", zz[n]);fclose(rf);fclose(wf); }
问答题下列给定程序中,函数fun()的功能是计算并输出 high以内的素数之和。high由主函数传给fun()函数。 例如:若high的值为100,则函数的解为1060。 请改正程序中的错误,使它能得到正确结果。 注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。 [试题源程序] #include<conio.h> #include<stdio.h> #include<math.h> int fun(int high) int sum=0,n=0,j,yes; while(high>=2) yes=1; for(j=2;j<=high/2;j++) /**********************found***********************/ ifhigh%j==0 yes=0; break; /***********************found***********************/ if(yes==0) sum+=high; n++; high--; return sum; main() clrscr(); printf("%d/n",fun(100));
问答题请编写一个函数proc(),它的功能是:比较2个字符串的长度(不得调用C语言中求字符串长度的函数),函数返回较长的字符串。若2个字符串长度相等,则返回第1个字符串。
例如,若输入jiangxi<Enter>
beijing<Enter>
则函数返回jiangxi。
注意:部分源程序给出如下。
请勿改动main()函数和其他函数中的任何内容,仅在函数proc()的花括号中填入所编写的若干语句。
试题程序:
#include<stdio.h>
char*proc(char*s, char*t)
{
}
void main()
{
char a[20], b[10], *p, *q;
printf("Input 1th string:");
gets(a);
printf("Input 2th string:");
gets(b);
printf("%s", proc(a, b));
}
问答题给定程序MODI1.C中函数fun的功能是:按以下递归公式求函数值。例如,当给n输入5时,函数值为18;当给n输入3时,函数值为14。请改正程序中的错误,使它能得出正确结果。注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。#include<stdio.h>/**********found**********/intfun(n){intc;/**********found**********/if(n=1)c=10;elsec=fun(n-1)+2;return(c);}main(){intn;printf("Entern:");scanf("%d",printf("Theresult:%d/n/n",fun(n));}
