编写函数fun(),它的功能是;根据以下公式求p的值,结果由函数值带回。m与n为两个正数且要求m>n。
P=m!/n!(m-n)!),例如:m=12,n=8时,运行结果为495.000000。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
include <conio.h>
include <stdio.h>
float fun (int m, int n)
{
}
main()
{
clrscr() ;
printf ("p=%f\n", fun (12,8) ) ;
}
第1题
设有如下程序:
main()
{int n1,n2;
scanf("%d",&n2);
while(n2!=0)
{ n1=n2%10;
n2=n2/10;
printf("%d",n1);
}
}
程序运行后,如果从键盘上输入1298,贝愉出结果为【 】。
第2题
以下程序的功能是输出如下形式的方阵:
13 14 15 16
9 10 11 12
5 6 7 8
1 2 3 4
请填空。
main()
{ int i,i,x;
for(j=4; j______; j--)
{ for(i=1; i<4; i++)
{ x=(j-1)*4+______;
printf("%4d",x);
}
printf("\n");
}
第3题
值返回,平均分存放在形参aver所指的存储单元中。例如输入8名学生的成绩:
80.5 60 72 90.5 98 51.5 88 64
则低于平均分的学生人数为4(平均分为75.5625)。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
include <stdio.h>
include <conio.h>
define N 20
int fun(float *s, iht n,float *aver)
{ float ave ,t=0.0;
int count=0,k,i;
for(k=0;k<n;k++)
/*************found**************/
t=s[k];
ave=t/n;
for(i=0;i<n;i++)
if(s[i]<ave) count++;
/*************found**************/
*aver=&ave;
return count;
}
main()
{ float s[30],aver;
int m,i;
clrscr();
printf("\nPlease enter m: "); scanf
("%d",&m);
printf("\nPlease enter %d mark :\n",m);
for(i=0;i printf("\nThe number of students :
%d\n",fun(s,m,&aver));
printf("Ave=%f\n",aver);
}
第4题
串。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun()的横线上填入所编写的若干表达式或语句。
试题程序:
include<stdio.h>
include<conio.h>
void fun(char *s)
{
int i=0;
char *p=s;
while(【 】)
{
if (*p>='a'&&*p<='z')
{
s[i]=*p;
【 】;
}
p++;
}
s[i]=【 】;
}
main()
{
char str[80];
clrscr();
printf("\nEnter a string:");
gets(str);
printf("\n\nThe string is:\%s\n",str);
fun(str);
printf("\n\nThe string of changing
is:\%s\n",str);
}
第5题
数;并把该整数中各位上最大的数字值作为函数值返回。例如,若输入无符号整数30800,则数字值为零的个数为3,各位上数字值最大的是8。
请改正函数fun中指定部位的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!
第6题
小数和a[1]中的数对调。
请改正程序中的错误,使它能得到正确结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
include <conio.h>
include <stdio.h>
define N 20
void fun(int *a,int n)
{
int i, m,t,k;
/*************found**************/
for(i=O; i<n; i++)
{
m==i;
for(k=i; k<n; k++)
if(a[k]<a[m])
/*************found**************/
k=m;
t=a[i];
a[i]=a[m];
a[m]=t;
}
}
main()
{
int x,b[N]={11,5,12,0,3,6,9,7,10,8},
n=10,i;
clrscr();
for(i=0; i<n; i++)
printf("%d",b[i]);
printf("\n");
fun(b,n);
for(i=0; i<n; i++)
printf("%d",b[i]);
printf("\n");
}
第7题
在数组中的位置。若找到,则返回其下标值:反之,则返回-1。
折半查找的基本算法是:每次查找前先确定数组中待查的范围:low和high(low<high),然后把m与中间位置(mid)中元素的值进行比较。如果m的值大于中间位置元素中的值,则下一次的查找范围放在中间位置之后的元素中;反之,下次查找范围落在中间位置之前的元素中。直到low>high,查找结束。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
include <stdio.h>
define N 10
/*************found*********************/
void fun(int a[],int m)
{ int low--0,high=N-l,mid;
while (low<=high)
{ mid=(low+high)/2;
if(m<a[mid])
high=mid-1;
/*************found*********************/
else if(m>=a [mid])
low=mid+1;
else return(mid);
}
return(-1);
}
main ()
{ int i,a[N]={-3,4,7,9,13,24,67,89,100,180},k,m;
printf ("a数组中的数据如下: ");
for(i=0;i<N;i++) printf("%d",a[i]);
printf ("Enter m: "); scanf ("%d", &m);
k=fun (a,m);
if (k>=0) printf ("m=%d, index=%d\n",m, k);
else printf("Not be found!\n");
}
第8题
原字符串,截取后的字符存放在str2所指的字符数组中,n中存放需截取的字符个数。
例如:当str1=“cdefghij”,然后输入4,则str2=“cdef”。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun()的横线上填入所编写的若干表达式或语句。
试题程序:
include<stdio.h>
include<conio.h>
define LEN 80
main()
{
char str1[LEN),str2[LEN);
int n,i;
clrscr();
printf(“Enter the string:\n”);
gets(str1);
printf“Enter the position of the string
deleted:”);
scanf(【 】);
for(i=0;i<n;i++)
【 】
str2[i]=‘\0’;
printf(“The new string is:%s\n”,【 】);
}
第9题
已知字符A的ASCII代码值为65,以下程序运行时若从键盘输入:B33<回车>,则输出结果是【 】。
include
main()
{ char a, b;
a=getchar(); scanf("% d", &b);
a=a-'A'+'0'; b=b*2;
printf("% c % c\n", a, b);
}
第10题
在t中。例如,当s中的数为7654321时,t中的数为642。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
include<stdio.h>
include <conio.h>
/*************found**************/
void fun(long s,long t)
{ long s1=10;
s/=10;
*t=s%10;
/*************found**************/
while(s<0)
{ s=s/100;
*t=s%10*s1+*t;
s1=s1*10;
}
}
main()
{ long s, t;
clrscr();
printf("\nPlease enter s: "); scanf
("%ld",&s);
fun(s,&t);
printf("The result is: %ld\n ",t);
}
为了保护您的账号安全,请在“上学吧”公众号进行验证,点击“官网服务”-“账号验证”后输入验证码“”完成验证,验证成功后方可继续查看答案!