问答题给定程序中,函数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);}
问答题编写一个函数,输入n个字符串,串与串之间以回车键分隔,找出最短字符串中第一个字符串,传回该串地址(用一个新串“*”作为结束输入的标志)。 注意:部分源程序已给出。 请勿改动主函数main和其他函数中的任何内容,仅在函数proc的花括号中填入所编写的若干语句。 试题程序: #include<stdio.h> #include<string.h> #include<conio.h> char*fun(char(*s)[100],int num) main() char str[10][100],*min; int n,i=0; FILE*out:printf("input strings with'*'asend:"); gets(str[i]); strcpy(str[3],"some"); strcpy(str[4],"tool?!?"; fprintf(out,"%s",fun(str,5)); puts(str[i]); while(!strcmp(str[i],"*")==0) i++; gets(str[i]); puts(str[i]); n=1; min=fun(str,n); printf("/nmin=%s/n",min); out=open("outfile.dat","w"); strepy(str[0],"just,"); strcpy(str[1],"a"); strcpy(str[2],"test"); fclose(out);
问答题人员的记录由编号和出生年、月、日组成,N名人员的数据已在主函数中存入结构体数组std中。函数fun的功能是:找出指定出生年份的人员,将其数据放在形参k所指的数组中,由主函数输出,同时由函数值返回满足指定条件的人数。 请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。 注意:源程序存放在考生文件夹下的BLANK1.C中。 不得增行或删行,也不得更改程序的结构!1 #include<stdio.h>2 #define N 83 typedef struct4 { int num;5 int year,month,day;6 } STU;7 int fun(STU *std, STU *k, int year)8 { int i,n=0;9 for(i=0;i<N;i++)10 /**********found**********/11 if(__1__==year)12 /**********found**********/13 k[n++]=__2__;14 /**********found**********/15 return( __3__);16 }17 main()18 {STU std[N]={{1,1984,2,15},{2,1983,9,21},{3,1984,9,1},{4,1983,7,15},{5,1985,9,28},{6,1982,11,15},{7,1982,6,22},{8,1984,8,19}};19 STU k[N];int i,n,year;20 printf(''Enter a year : '');scanf(''%d'',&year);21 n=fun(std,k,year);22 if(n==0)23 printf(''\nNo petson was born\n%d\n'',year);24 else25 { printf(''\nThese persons were born\ n%d\n'',year);26 for(1=0; i<n;i++)27 printf(''%d %d-%d-%d\n'', k[i].num,k[i].year,k[i].month,k[i].day);28 }29 }
问答题函数fun的功能是:输出a所指数组中的前n个数据,要求每行输出5个数。
请在程序的下画线处填入正确的内容并把下画线删除,使程序得出正确的结果。
注意:源程序存放在考生文件夹下的BIANK1.C中。不得增行或删行,也不得更改程序的结构!
试题程序:
#include < stdio.h >
#include < stdlib.h >
void fun(int*a,int 13)
{int i;
for(i=0;i < n;i++)
{
/*********found*********/
if(
【1】
==0)
/*********found*********/
printf("
【2】
");
/*********found*********/
printf("%d",
【3】
);
}
}
main()
{int a[100]={0),i,n;
n=22;
for(i=0;i < n;i++)
a[i]=rand()%21;
fun(a,n);
printf("/n");
}
问答题下列程序定义了N×N的二维数组,并在主函数中赋值。请编写一个函数fun(),函数的功能是:求数组周边元素的平方和,并作为函数值返回给主函数。例如,若数组a中的值为 0 1 2 7 9 1 11 21 5 5 2 21 6 11 1 9 7 9 10 2 5 4 1 4 1 则返回主程序后s的值应为310。 [注意] 部分源程序给出如下。 请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。 [试题源程序] #include <stdio.h> #include <conio.h> #include <stdlib.h> #define N 5 int fun(int w[][N]) main() int a[N][N]=(0, 1, 2, 7, 9, 1, 11, 21, 5, 5, 2, 21, 6, 11, 1, 9, 7, 9, 10, 2, 5, 4, 1, 4, 1); int i, j; int s; clrscr() 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: %d/n", s);
问答题printf"Input 2th string: ");
问答题下列给定程序中,函数fun的功能是:计算如下公式直到≤10-3,并且把计算结果作为函数值返回。例如,若形参e的值为1e一3,则函数返回值为0.551690。请在程序的下画线处填入正确的内容并将下画线删除,使程序得出正确的结果。注意:部分源程序给出如下。不得增行或删行,也不得更改程序的结构!试题程序:#include<stdio.h>doublefun(doublee){inti,k;doubles,t,x;s=0;k=1;i=2;/*********found*********/x=【1】/4;/*********found*********/while(x【2】e){s=s+k*x;k=k*(一1);t=2*i;/*********found*********/x=【3】/(t*t);i++;}returns;}main(){doublee=1e一3;printf("\nTheresultis:%f\n",fun(e));}
问答题程序定义了N×N的二维数组,并在主函数中自动赋值。请编写函数fun(inta[][N],intn),该函数的功能是:使数组左下半三角元素中的值乘以n。例如,若n的值为3,a数组中的值为:则返回主程序后a数组中的值应为:注意:部分源程序给出如下。请勿改动函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。试题程序:#include<stdio.h>#include<conio.h>#include<stdlib.h>#defineN5voidfun(inta[][N],intn){}main(){inta[N][N],n,i,j;printf("*****Thearray*****\n");for(i=0;i<N,i++){for(j=0;j<N;j++){a[i][j]=rand()%10;printf("%4d",a[i][j]);}printf("\n");}n=rand()%4;printf("n=%4d\n",n);fun(a,n);printf("*****THERESULT*****\n");for(i=0;i<N;i++){for(j=0;j<N;j++)printf("%4d",a[i][j]);printf("\n");}}
问答题请编写一个函数fun,它的功能是将一个表示正整数的数字字符串转换为一个整数(不得调用C语言提供的将字符串转换为整数的函数)。例如,若输入字符串“1234”,则函数把它转换为整数值1234。函数fun中给出的语句仅供参考。
注意:部分源程序存在文件PROG1.C中。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入编写的若干语句。
给定源程序如下。
#include<stdio.h>
#include<string.h>
long fun(char
*
p)
{
/*以下代码仅供参考*/
int i,len;/*len为串长*/
long x=0:
len=strlen(p);
/★以下完成数字字符串转换为一个数字。
注意:字符"0"不是数字0★/
return x;
}
main(),/*主函数*/
{ char s[6];
long n;
printf("Enter a string:/n");
gets(s);
n=fun(s);
printf("%ld/n",n);
}
问答题下列给定的程序中,函数fun的功能是:计算并输出k以内最大的10个能被13或17整除的自然数之和。k的值由主函数传入,若k的值为500,则函数的值为4622。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动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));
}
问答题给定程序MODI1.C中函数fun的功能是:删除P所指字符串中的所有空白字符(包括制表符、回车符及换行符)。
输入字符串时用"#"结束输入。
请改正程序中的错误,使它能输出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
#include<string.h>
#include<stdio.h>
#include<ctype.h>
fun(char*P)
{int i,t;char c[80];
/**********found**********/
For(i=0,t=0;p[i];i++)
if(!isspace(*(p+i)))c[t++]=p[i];
/**********found**********/
c[t]="/0";
strcpy(p,c);
}
main()
{char c,s[80];
int i=0;
printf("Input a string:");
c=getchar();
while(c!="#")
{s[i]=c;i++;c=getchar();)
s[i]="/0";
fun(s);
puts(s);
}
问答题函数fun的功能是:将一副扑克牌编号为1,2,3,…,53,54,以某种特定的方式洗牌,这种方式是将这副牌分成两半,然后将它们交叉,并始终保持编号为1的牌在最上方,如第一次这样洗牌后的结果为:1,28,2,29,…,53,27,54。两次洗牌后的结果为:1,41,28,15,2,42…,53,40,27,14,54程序的功能是:输出经过n次这样洗牌后的结果。请在程序的下画线处填入正确的内容,并把下画线删除,使程序得出正确的结果。注意:源程序存放在考生文件夹下的BLANK1.C中。不得增行或删行,也不得更改程序的结构!试题程序:#include<stdio.h>void fun(int a[55],int n){int i,k;/**********found**********/int【1】[55];for(i=0;i<n;i++){for(k=1;k<=27;k++){b[2*k-1]=a[k];/**********found**********/b[【2】*k]=a[k+27];}for(k=1;k<=54;k++)/**********found**********/a[k]=【3】;}}main(){int m,a[55],i;for(i=1;i<55;i++)a[i]=i;pfinff("请输入洗牌次数:");scanf("%d",&m);fun(a,m);for(i=1;i<55;i++)printf("%d,",a[i]);printf("\n");}
问答题给定函数MODI1.C中函数fun的功能是:将一个由八进制数字字符组成的字符串转换为与其面值相等的十进制整数。规定输入的字符串最多只能包含5位八进制数字字符。
例如,若输入:77777,则输出将是:32767。
请改正程序中的错误,使它能得出正确结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
#include
#include
#include
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;2nL 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]'7')
{print;f("Error:%c not is
ocatal digits!/n/n",s[i]);exit:(0);)
print;f("The original string:
"); puts(s);
n=fun(s);
printf("/n%s is convered to
integer number: %d/n/n",s,n);
}
问答题编写函数fun,其功能是:将s所指字符串中除了下标为奇数同时ASCII码值也为奇数的字符之外,其余的所有字符全部删除,串中剩余字符所形成的一个新串放在t所指的数组中。例如,若s所指字符串的内容为“ABCDEFG12345”,其中字符A的ASCII码值为奇数,但所在元素的下标为偶数,因此需要删除;而字符1的ASCII码值为奇数,所在数组中的下标也为奇数,因此不应当删除,其他依此类推。最后t所指数组中的内容应为“135”。注意:部分源程序给出如下。请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。试题程序:#include<conio.h>#include<stdio.h>#include<string.h>void fun(char *s,char t[]){}main(){ char s[100],t[100]; printf("knPlease enter string s:"); scanf("%s",s); fun(s,t); printf("knThe result is:%s\n",t);}
