Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9220685
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T03:24:28+00:00 2026-06-18T03:24:28+00:00

Is this the correct way to write the normal distribution function http://en.wikipedia.org/wiki/Normal_distribution or should

  • 0

Is this the correct way to write the normal distribution function http://en.wikipedia.org/wiki/Normal_distribution or should I be using the pow function? I am really confused so help would be greatly appreciated 🙂

#include <stdio.h>
#define _USE_MATH_DEFINES 
#include <math.h>
#include <stdlib.h>
int main()
{
double u,s, N, x1,math1, math2, math3,n, v, x;

printf("Enter Mean: ");
scanf("%lf", &u);
printf("Enter Standard Deviation: ");
scanf("%lf", &s);
printf("Enter Number Of Inputs: ");
scanf("%lf", &N);

    for (v=1; v<=N; v++)
    {
    printf("Enter Value: ");
    scanf("%lf", &x);
    n=(-1/2);
    printf("f(x)= ");
    math1 =1/(s*sqrt(2*M_PI));
    math2= (x-u)/s * (x-u)/s;
    math3= M_E * exp(n);
    x1 = math1 * exp(math3)*exp(math2);
    printf("%lf  \n", x1);
    }
system("Pause");
 }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T03:24:29+00:00Added an answer on June 18, 2026 at 3:24 am

    It’s too hard to read your code, but I can tell it’s wrong. Here is a short version:

    double twopi = 8.0 * atan(1.0); // preferable to using M_PI
    double x = ..., sigma = ..., mu = ...;
    double y = (1.0 / (sigma * sqrt(twopi))) *
        exp(-(x - mu)*(x - mu) / (2.0 * sigma * sigma));
    

    Notice how I translate the mathematical formula directly to an expression in C… this makes it easy to verify that the code is correct. It’s a bit harder when you use a bunch of temporary variables math1, math2, math3…

    Remember: exp() is the same thing as its counterpart in mathematics, exp. So exp(x) is ex. Once you realize this, you will see the errors in your code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What is the correct way to write this JPA query? I am just guessing
whats the correct way to write a function that can accept different input's and
Is this the correct way to create an Object and place a function inside
Is this the correct way to write a PDO update statement? I based it
Is this the correct way to write this xslt ? First is the XML
Is this the correct way to do it? <a id=load href=# class=btn load onclick=request(this);
Is this the correct way to obtain the most negative double in Java? double
Is this the correct way to pass two ids in jQuery? I am having
Is this the correct way to update a ProgressBar when playing Media? I figured
This is a simple question: Is this a correct way to get an integer

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.