【问题标题】:Standard Deviation Program标准差计划
【发布时间】:2013-01-24 10:54:29
【问题描述】:

这是指令:编写一个程序,开始询问用户的平均值 u 和 正态分布的标准差 s (参见维基文章http://en.wikipedia.org/wiki/Normal_distribution 然后程序请求一个 N,然后请求 N 个值 x。对于每个 x 它 将 f(x) 写到屏幕上。 请注意,程序仅向用户询问 u、s 和 N 一次。之后它 逐一要求 x 的 N 个值。在每个值 x 之后,它写出 对应的函数值。 当然,为此使用双精度并使用平方根和 标准数学库中的指数函数。

这是我目前的代码,但我无法让 N 工作。

#include <stdio.h>
#define PI 3.141592653589793238462643383
#define E 2.7182818284590452353602874713526624977572470937
#include <math.h>
#include <stdlib.h>
int main()
{
double u,s,N,x,math1, math2, math3,n,;
printf("Enter Mean: \n");
scanf("%d", &u);
printf("Enter Deviation: \n");
scanf("%d", &s);


    n=1/2;
math1 =1/(u*sqrt(2*PI));
math2= (x-u)/s * (x-u)/s;
math3= E * exp(n);
x = math1 * exp(math3)*exp(math2);
printf("%d \n", x);
system("Pause");
}

【问题讨论】:

    标签: c


    【解决方案1】:
    n=1/2;
    

    这将等于 0,因为 1 是整数,2 是整数,而 1 除以 2 是整数数学中的 0。

    试试1.0/2.0

    确保每个其他除法的一侧或两侧都有一个双精度数,否则它将作为整数数学完成

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-01-28
      • 2016-04-14
      • 2015-11-20
      • 2020-08-13
      • 2019-08-15
      • 1970-01-01
      • 1970-01-01
      • 2023-04-11
      相关资源
      最近更新 更多