请完成函数fun(),它的功能是:用选择法对数组中n个元素按从大到小的顺序进行排序。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在下划线上填入所需的内容。
include<stdio.h>
define N 20
void fun(int a[],int n)
{
int i,j,t,p;
for(j=0;j<n-1; 1 )
{ p=j;
for(i=j;i<n;i++)
if(a[i] 2 a[p]
p=i;
t=a[p];
a[p]=a[j];
a[ 3 ]=t;
}
}
main()
{int a[N]={11,32,-5,2,14},i,m=5;
for(i=0;i<m;i++)
printf("%d\n",a[i});
fun(a,m);
for(i=0;i<m;i++)
printf("%d"a[i]);
}
第1题
三角形,则返回3,若是等腰三角形,则返回2,若能构成三角形则返回1,若不能,则返回0。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
include <math. h>
int fun(int a, int b, int c)
{ if (a+b>c&&b+c>a&&a+c>b)
{ if (a==b&&b==c)
/*************found**************/
return 1;
else if(a==b|| b==c||a==c)
return 2;
/*************found**************/
else return 3;
}
else return 0;
}
main ( )
{ int a,b, c, shape;
printf("\nInput a,b,c: ");
scanf ("%d%d%d", &a, &b, &c);
printf ("\na=%d, b=%d, c=%d\n",a,b,c);
shape=fun (a,b, c);
printf ("\n\nThe shape : %d\n", shape);
}
第2题
请补充main函数,该函数的功能是:输入两个正整数m和n,求这两个数的最大公约和最小公倍数。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在 main函数的横线上填入所编写的若干表达式或语句。
试题程序:
include <stdio.h>
main ( )
{
int a, b, n, m, t;
clrscr ();
printf ("\nInput two numbers: \n");
scanf ("%d, %d", &n, &m);
if (n<m)
{
a=m;
b=n;
}
else
{
a=n;
b=m;
}
while(【 】)
{
t=【 】
a=b;
b=t;
}
printf ("greatest con. non divisor:
%d\n", a);
printf ("least common multiple:
%d\n",【 】);
}
第3题
:将a数的十位和个位数依次放在c数的十位和千位上,b数的十位和个位数依次放在c数的百位和个位上。
例如,当a=45时,b=12,调用到该函数后,c=5142。
注意:部分源程序给出如下.
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
include <stdio.h>
include<conio.h>
void fun(int a ,int b, long *c)
{
}
main ( )
{
int a,b;
long c;
clrscr();
printf("Input a ,b:");
scanf(,%d%d",&a,&b);
fun(a,b,&c);
printf("The result is :%ld\n",c);
}
第4题
请编写函数fun(),该函数的功能是:计算并输出
S=1+(1+20.5)+(1+20.5+30.5)+…+(1+20.5+30.5+…+n0.5)
例如,若主函数从键盘给n输入20后,则输出为
s=534.188884。
注意;部分源程序给出如下。
请勿改动主函数main 和其他函数中的任何内容,仅在函数fun 的花括号中填入所编写的若干语句。
试题程序:
include <math. h>
include <stdio. h>
double fun(int n)
{
}
main()
{
int n;
double s;
printf("\n\nInput n: ");
scanf ("%d", &n);
s=fun (n)
printf ("\n\ns=%f\n\n", s);
}
第5题
高于平均分的分数放在叩所指的数组中。
例如,当score数组中的数据为24,35,88,76,90,54, 59,66,96时,函数返回的人数应该是5,up中的数据应为88, 76, 90, 66, 96。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
include <conio.h>
include <stdio.h>
include <string.h>
int fun(int score[],int m,int up[])
{
}
main()
{
int i,n,up[9];
int score[9]={24,35,88,76,90,54,
59,66,96};
clrscr();
n=fun(score,9,up);
printf("\nup to the average score are:");
for(i=0;i<n;i++)
printf("%d",up[i]);
}
第6题
串t中(规定第一个字符放在第0位中)。
例如:字符串中的数据为ADFESHDI,则输出应当是 AFESDI。
请改正程序中的错误,使它能得到正确结果。
注意;不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
include <conio.h>
include <stdio.h>
include <string.h>
define N 80
/************found*************/
void fun(char s,char t[])
{
int i,j=0;
for(i=0;i<strlen(s);i++)
/*********found*+************/
if(i%2=0 || s[i]%2!=0)
t[j++]=s[i];
t[j]='\0';
}
main()
{
char s[N],t[N];
clrscr();
printf("\nPlease enter string s:");
gets(s);
fun(s,t);
printf("\nThe result is:%s\n",t);
}
第7题
字符依次存放到c数组中,形成一个新的字符串。
例如:a中的字符串为fshADfg,b中的字符串为sdAEdi,则c中的字符串应为fdAADf。
请改正程序中的错误,使它能得到正确结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
include <stdio.h>
include <strinq.h>
void fun(char *p,char *q,char *c)
{int k=0;
while(*p || *q)
/**********found**************/
{ if (*p<=*q)
c[k]=*q;
else c[k]:*p;
if(*p) p++;
if(*q)q++;
/**+**********found**************/
k++
}
}
main()
{char a[10]="fshADfg",b[10]="sdAEdi",
c[80]={'\0');
fun(a,b,c);
printf("The string a:");puts(a);
printf("The string b:");puts(b);
printf("The result:");puts(c);
}
第8题
量eps输入 0.0005时,应当输出Pi=3.140578。
n/2=1+1/3+1/3*2/5+1/3*2/5*3/7+1/3*2/5*3/7*4/9……
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
include <conio.h>
include <stdio.h>
include <math.h>
double fun(double eps)
{double s,t; int n=t;
s=0.0;
/*************found**************/
t=1;
/*************found**************/
while(t>eps)
{ s+=t;
t=t*n/(2*n+1);
n++;
}
/*************found**************/
return (s);
}
main()
{ double x;
printf("\nPlease enter a precision: ");
scanf("%1f",&x);
printf("\nPi=%1f\n ",fun(x));
}
第9题
请补充函数fun(char *s),该函数的功能是把字符串中的内容逆置。
例如:字符串中原有的字符串为abcde,则调用该函数后,串中的内容变为edcba。
注意;部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun()的横线上填入所编写的若干表达式或语句。
试题程序:
$include<string.h>
include<conio.h>
include<stdio.h>
define N 81
void fun(char*s)
{
int i=0,t,n=strlen(s);
for(;【 】;i++)
{
t=*(s+i);
【 】;
【 】;
}
}
main()
{
char a[N];
clrscr();
printf("Enter a string:");
gets(a);
printf("The original string is:");
puts(a);
fun(a);
printf("\n");
printf("The string after modified:");
puts(a);
}
第10题
给定程序中,函数fun()的功能是:使数组中的元素的值缩小5倍。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
include<stdio.h>
include<conio.h>
float m[10];
/*************found**************/
int fun (void)
{
int j;
printf("In subfunc after calling\n");
for(j=O;j<lO;j++)
{
;
/*************found**************/
print ("%f ",m[j]%5);
}
}
main()
{
int i;
printf ("In main before calling\n");
for (i=0;i<10;i++)
{
m[i]=i+20;
printf("%f ",m[i]);
}
fun();
printf("\nIn main after calling\n");
for(i=O; i<10;i++)
printf("%f ",m[i]/5);
}
为了保护您的账号安全,请在“上学吧”公众号进行验证,点击“官网服务”-“账号验证”后输入验证码“”完成验证,验证成功后方可继续查看答案!