使用scanf输出x的标准逻辑函数?

使用scanf输出x的标准逻辑函数?,c,scanf,C,Scanf,我需要创建一个代码,提示某人输入一个浮点数,并使用scanf输出应用于输入数字的标准逻辑函数的值 物流职能定义为: L f(x) = ---------------------- 1 + e^(-k(x - x0)) 以下是我到目前为止的情况: #include <stdio.h> #include <stdlib.h> #include <time.h> #include <mat

我需要创建一个代码,提示某人输入一个浮点数,并使用scanf输出应用于输入数字的标准逻辑函数的值

物流职能定义为:

                     L

 f(x) = ----------------------

           1 + e^(-k(x - x0))
以下是我到目前为止的情况:

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
int main()
{
float number;
 printf("Enter an integer: ");
  scanf("%f",&number);
}
#包括
#包括
#包括
#包括
int main()
{
浮点数;
printf(“输入一个整数:”);
scanf(“%f”和编号);
}

所以我的问题是,为了让程序输出正确的值,我可以编写什么代码?我认为最重要的是,如何将逻辑功能纳入代码中?所有变量都应声明为float。提前非常感谢

只需编写一个进行计算的函数,并按照下面给出的代码调用它即可。希望它能达到你的目的

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>


float logistic(float x, float x0, float k)
{

    return (1 / ( 1 - exp(-k * ( x - x0)))) ;
}

int main()
{
    float number;
    printf("Enter an integer: ");
    scanf("%f",&number);
   /* Let x0= 1.0 and  k= 2.0 for simplicity */
   /* You can change it whenever you want */
   float x0= 1.0, k= 2.0;

   printf(" Logistic value is %f ",logistic(number, x0 , k) );
}
#包括
#包括
#包括
#包括
浮动物流(浮动x、浮动x0、浮动k)
{
收益率(1/(1-exp(-k*(x-x0));
}
int main()
{
浮点数;
printf(“输入一个整数:”);
scanf(“%f”和编号);
/*为了简单起见,设x0=1.0和k=2.0*/
/*你可以随时更改它*/
浮点数x0=1.0,k=2.0;
printf(“逻辑值为%f”,逻辑(数字,x0,k));
}

谢谢大家的建议。

x0和k的值是多少?这是学习c的一个很好的练习……@riov8x0=0和k=1您知道如何用c编写表达式吗?如果没有,你可能需要复习基础知识。你到底被卡在哪一部分?您可能会发现该函数很有用。欢迎使用@Ryan James。如果你觉得答案有用,你能接受吗?为什么你需要这么多临时任务?这一切都可以在一个简单的返回语句中完成是的,我本来可以做到,但我不想让它对你和将来可能看到它的人来说变得复杂。@AkhileshPandey我不认为这样的表达式是多么复杂,因为它只是一个逻辑函数的实现,OP显然知道。如果有什么不同的话,你的
temp
变量实际上会让事情变得更复杂,因为很难看到原始表达式。好吧,那么我会修改它,这不是什么大问题。谢谢@Fei Xiang