简答题 C语言
题号 #2547467

请编写函数proc(),它的功能是计算:
s=(1-In(1)-ln(2)-In(3)-…-In(m))2
S作为函数值返回。
在C语言中可调用log(n)函数求In(n)。log函数的引用说明是double log(double x)。
例如,若m的值为10,则proc()函数值为198.934454。
注意;部分源程序给出如下。
请勿改动main()函数和其他函数中的任何内容,仅在函数proc()的花括号中填人所编写的若干语句。
试题程序:
#include<stdlib.h>
#include<conio.h>
#include<stdio.h>
#include<math.h>
double proc(int m)
{
void main()
{
system(”CLS”);
printf(”%f\n”,proc(10));
}

进入在线模考

参考答案

暂无

答案解析

(m)
{
;
doubles=1.0;//s的初值赋为
for(i=1;i<=;i++)//从到
s=s-log(i);将其求得的差放到中
(s*);最后把其平方值返回到主函
数中)
【解析】首先我们应定义一个变量来表示其和,一个来表示其项数,然后通过循环,求得其差值,最后把和的平方返回到主函数中。

你可能感兴趣的试题

1

字符串str由数字字符组成(长度不超过5个字符),可看作任意进制的数,请补充函数proc(),该函数的功能是:把str字符串从二进制转换成十进制的数,结果保存在数组XX中,由函数返回转换后数组XX的实际长度。其中X表示str原来的进制,Y表示要转换成的进制。例如,输入str=”
1011”,x=2,,r=10,结果输出11。
注意:部分源程序给出如下。
请勿改动main()函数和其他函数中的任何内容,仅在函数proc()的横线上填入所编写的若干表达式或语句。
试题程序:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define M 8
int xx[M];
int proc(char * str,int x,int y)
{
int sum;
int i=0;
char * p=str;
for(i=0;i<M;i++)
xx[i]=0;

sum= 【1】 :
p++;
while(*p)
{
sum=sum*x+*p-'0';
p++;
}
i=0;
while(sum!=0)
{
xx[i]=【2】 ;
[3]  ;
i++:
}
return i;
}
void main()
{
char str[6];
int i;
int n;
int x:
int y;
printf(”Enter a string made up of '0' to '9' digits
character:");
gets(str);
if(strlen(str)>5)
(
printf(”Error:string too longer!,please input a
gain!\n\n”);
exit(0);
)
for(i=0;str[i];i++)
if(str[i]<'0' ||str[i]2>'9'
{
printf(”Error:%c not is '0' to '9' digits character!\n\n”,str[i]);
exit(O);
)
printf(”The original string:”);
puts(str);
printf(”\nlNPUT x=”);
scanf(”%d”,&x);
printf(”\nlNPUT y=”);
scanf(”%d”,&y);
n=proc(str,x,y);
prim[(”\n%s is convered to”,str);
for(i=1;i>=0;i--)
print[(”%d\n”,xx[i]/n):
}

找试题 · 找答案 · 找资料 在线模考