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

  • Home
  • SEARCH
  • 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 6545603
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:36:21+00:00 2026-05-25T11:36:21+00:00

In my quest to learn C I’ve come across a task which is causing

  • 0

In my quest to learn C I’ve come across a task which is causing me a few problems. I need to make an equation for the approximate value of the formulae n!, which can be described as:

n! = n^n*e^(-n)*sqrt(2(2*n+1/3)*PI), however I simply cannot get my values to corrospond with the actual value. 5! = 120ish

I can get a value of some 148ish

Can’t figure out where my code is wrong:

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

#define PI 3.14156
#define E_CONST 2.7828

int main ()
{

double num;
double calc, first, second, third, fourth;

printf("Give an int: ");
scanf("%lf", &num);


first = pow(num , num);

second = pow(E_CONST, -num);

third = (2 * num + 1/3);

fourth = sqrt(2*third*PI);

//calc = first * second * fourth;

calc = pow(num, num) * pow(E_CONST, -num) * sqrt(2*(2*num+(1/3))*PI);
printf("Input: %f", num);

printf("1: %.2f\n2: %.10f\n3: %.8f\n4: %.2f\n", first, second, third, fourth);

printf("\nInt was: %.2f\n\nApproximate number: %.5f", num, calc);

return 0;
}

Feel like i have tried everything. The code is a bit messy, but it’s because I’ve scrambled so much with it now.

  • 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-05-25T11:36:23+00:00Added an answer on May 25, 2026 at 11:36 am

    3.14156 is a bad value for PI: it’s better to use 3.1416, or 3.14159, or 4 * atan(1), or, for POSIX implementations, M_PI.

    2.7828 is a very bad value for e: it’s better to use 2.7183, or exp(1), or, for POSIX implementations, M_E.

    1/3 is integer division, the result is 0: it’s better to use 1.0/3.

    Also your approximation is incorrect. The correct approximation is

    n^n * e^(-n) * sqrt((2*n+1/3)*PI)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my quest to learn C++, I have come across dynamic and static libraries.
In my quest to learn javascript (which seems to be my latest source of
On my quest learning Java I come across one doubt. For sorting a unidimensional
on my quest to learn and improve my JavaScript I came across a script
In my ongoing quest to learn ruby by doing training exercises I came across
In my quest to learn ActionScript 3.0 I have stumbled across another situation where
I'm on a personal quest to learn how the rsync algorithm works. After some
In my quest in trying to learn more about OOP in PHP. I have
In the quest for localization I need to find all the string literals littered
As I continue my quest of learning functional programming, I've come to wonder if

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.