下列程序定义了N×N的二维数组,并在主函数中赋值。请编写函数fun(),函数的功能是:求出数组周边元素的平均值并作为函数值返回给主函数中的s。例如:若a数组中的值为
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])
{
}
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;
clrscr();
printf("*****The array*****\n ");
for (i=0; i<N; i++)
{ for (j=0;j<N;i++)
{printf("%4d ",a[i] [j]);}
printf("\n ");
}
s=fun(a);
printf("*****THE RESULT*****\n ");
printf("The sum is : %lf\n ",s);
}
第1题
下面程序的运行结果是( )。
include<stdio.h>
define SlZE 12
main()
{char s[SIZE];int i;
for(i=0;i<SIZE;i++) s[i]='A'+i+32;
sub(s,5,SIZE-1);
for(i=0;i<SIZE;i++)printf("%c",s[i]);
printf("\n");}
sub(char *a,int t1,int t2)
{ char ch;
while(t1<t2)
{ ch=*(a+t1);
*(a+t1)=*(a+t2);
*(a+t2)=ch;
t1++;t2--;
}
}
第2题
下列程序的功能:对输入的一行字符中的数字字符的字面值累加,输出此累加和,请填空。
include<stdio.h>
include<ctype.h>
main()
{ char c;
int a,s=0;
while(______)
if(isdigit(c))
{a=c-'0';s+=a;}
printf("s=%d",s);
}
第3题
个新串放在t所指的数组中。
例如,若s所指字符串中的内容为ABCDEFGl2345,其中字符B的ASCⅡ码值为偶数、…、字符2的ASCⅡ码值为偶数、…,都应当删除,其他依次类推。最后t所指的数组中的内容应是ACEGl35。
注定:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序;
include <stdio. h>
include<string.h>
include<conio. h>
void fun(char *s, char t[])
{
}
main ( )
{
char s[100],t [100];
clrscr ();
printf (,\nPlease enter string S: ");
scanf ("%s", s);
fun(s,t);
printf ("\nThe result is :%s\n",t);
}
第4题
正程序中的错误,使它能得到正确结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
include<stdio.h>
define N 20
void fun(int a[ ],int n)
{
int i,j,t,p;
/*************found*************/
for(j=0;j<n-1;j++) ;
{
p=j;
for(i=j;i<n;i++)
if(a[i)>a[p])
p=i;
t=a[p];
a[p]=a[i];
/*************found**************/
a[p]=t;
}
}
main()
{
int a[N]={11,32,-5,2,14},i,m=5;
printf(“排序前的数据:”);
for(i=0;i<m;i++)
printf(“%d”,a[i]);
printf(“\n”);
fun(a,m);
printf(“排序后的顺序:”);
for(i=0;i<m;i++)
printf(“%d”,a[i]);
printf(“\n”);
}
第5题
以下程序的输出结果是( )。
include<stdio.h>
fun()
{ int a=0;
a+=3;
printf("%d",A);
}
main()
{ int cc;
for(cc=1;cc<=4;cc++)
fun();
printf("\n");
}
第6题
下面程序的功能是:从输入的正整数中选3个数进行输出,要求这些数都是2的倍数,请填空。
main()
{ int a,i=0;
scanf("%d",&A);
do
{ if(a>0&&a%2==0)
{printf("%d\n",A);i++;}
if(i!=3)
{ scanf("%d",&A);}
}while(( ));
}
第7题
以下程序打开新文件f.txt,并调用字符输出函数将a数组中的字符写入其中,请填空。
include<stdio.h>
main( )
{________*fp;
char a[5]=(’1’,’2’,’3’,’4’,’5’),i;
fp=fopen(”f.txt”,”w”);
for(i=0;i<5;i++)fputc(a[i],fp);
fclose(fp);
}
第8题
下列给定程序中,函数fun()的功能是:在字符串的最前端加入n个*号,形成新串,并且覆盖原串。
注意:字符串的长度最长允许79。
请改正函数fun()中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序;
include <stdio.h>
include <strzng.h>
include <conio.h>
/*****************found***************/
void fun(char s[], int n)
{
char a[80],*p;
int i;
/*****************found***************/
s=p;
for(i=0; i<n; i++) a[i]='*';
do
{a[i]=*p;
/*****************found***************/
i++;
}while(*p);
a[i]=0;
strcpy(s,a);
}
main()
{ int n;char s[80];
clrscr();
printf("\nEnter a string:");gets(s);
printf("\nThe string\%s\n",s);
printf("\nEnter n(number of*):");scanf ("%d",&n);
fun(s,n);
printf("\nThe string after inster: \%s\n",s);
}
第9题
组b中并输出,把其他字符保存在N[10]中。
例如:当str1=“ab123456789cde090”时,结果为:
0: 2 1: 1 2: 1 3: 1 4: 1 5: 1 6: 1 7: 1 8: 1 9:2 other charactor:5
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun()的横线上填入所编写的若干表达式或语句。
试题程序:
include <stdio.h>
include <conio.h>
main()
{
int i,b[11];
char *str="abl23456789cde090";
char *p=str;
clrscr();
printf("***the origial data ***\n");
puts(str);
for(i=0;i<11;i++)
b[i]=0;
while(*p)
{
switch(【 】)
{
case '0':b[0]++;break;
case '1':b[1]++;break;
case '2':b[2]++;break;
case '3':b[3]++;break;
case '4':b[4]++;break;
case '5':b[5]++;break;
case '6':b[6]++;break;
case '7':b[7]++;break;
case '8':b[8]++;break;
case '9':b[9]++;break;
【 】
}
【 】
}
printf("****** the result ********\n");
for(i=0;i<10;i++)
printf("\n%d:%d",i,b[i]);
printf("\nother charactor:%d",b[i]);
}
第10题
中。
例如,若二维数组中的数据为:
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");
}
为了保护您的账号安全,请在“上学吧”公众号进行验证,点击“官网服务”-“账号验证”后输入验证码“”完成验证,验证成功后方可继续查看答案!