request for C code for factorial of any wish number

This is a discussion on request for C code for factorial of any wish number within the C Programming forums, part of the General Programming Boards category; hi I want to know if there is C code to obtain factorial of any wish number up to 15 ...

  1. #1
    Registered User
    Join Date
    May 2010
    Posts
    7

    request for C code for factorial of any wish number

    hi
    I want to know if there is C code to obtain factorial of any wish number up to 15 digits
    I really need this code

  2. #2
    msh
    msh is offline
    Novice
    Join Date
    Jul 2009
    Posts
    568
    Where should I mail the code to?

  3. #3
    Registered User
    Join Date
    May 2010
    Location
    Naypyidaw
    Posts
    1,314
    We are happy to assist if you have problem with your code. But you should show your initiatives.

  4. #4
    Registered User
    Join Date
    May 2010
    Posts
    7
    Quote Originally Posted by msh View Post
    Where should I mail the code to?
    Really thanks
    here: ssrssd2 [at] gmail [dot] com

  5. #5
    Registered User
    Join Date
    May 2010
    Posts
    7
    i show my initiatives but now i got to to class

  6. #6
    Registered User
    Join Date
    Jan 2009
    Location
    Australia
    Posts
    375
    I think you prove that a person's name is a reflection of their personality.

  7. #7
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    Location
    London, United Kingdom
    Posts
    2,094
    How lazy can you get for f sakes !?
    1. Get rid of gets(). Never ever ever use it again. Replace it with fgets() and use that instead.
    2. Get rid of void main and replace it with int main(void) and return 0 at the end of the function.
    3. Get rid of conio.h and other antiquated DOS crap headers.
    4. Don't cast the return value of malloc, even if you always always always make sure that stdlib.h is included.

  8. #8
    Registered User
    Join Date
    May 2010
    Posts
    7
    Quote Originally Posted by DeadPlanet View Post
    I think you prove that a person's name is a reflection of their personality.
    you misunderstood my nickname name

  9. #9
    Registered User
    Join Date
    May 2010
    Posts
    7
    what should i do now? explaining the situation? what do you care about!?

  10. #10
    Registered User
    Join Date
    Jan 2009
    Location
    Australia
    Posts
    375
    Trying it yourself is usually the first step.

  11. #11
    Registered User
    Join Date
    May 2010
    Posts
    7
    i tried some codes but none work for large numbers.
    i upload them

  12. #12
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    Location
    London, United Kingdom
    Posts
    2,094
    Upload those "codes". Let's take a look at "them".
    1. Get rid of gets(). Never ever ever use it again. Replace it with fgets() and use that instead.
    2. Get rid of void main and replace it with int main(void) and return 0 at the end of the function.
    3. Get rid of conio.h and other antiquated DOS crap headers.
    4. Don't cast the return value of malloc, even if you always always always make sure that stdlib.h is included.

  13. #13
    Registered User
    Join Date
    May 2010
    Posts
    7
    :">
    Code:
    #include<conio.h>
    #include<stdio.h>
    #include<math.h>
    main()
    {
    clrscr();
    float n,i;
    float fact=1;
    printf("\ninsert the number:");
    scanf("%f",&n);
    for(i=1;i<=n;i++)
    {
    fact*=i;
    }
    printf("\nthe factorile %f is:\n%f",n,fact);
    getch();
    return 0;
    }

  14. #14
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    Location
    London, United Kingdom
    Posts
    2,094
    How does this work for your 15 digits "wish number"?
    1. Get rid of gets(). Never ever ever use it again. Replace it with fgets() and use that instead.
    2. Get rid of void main and replace it with int main(void) and return 0 at the end of the function.
    3. Get rid of conio.h and other antiquated DOS crap headers.
    4. Don't cast the return value of malloc, even if you always always always make sure that stdlib.h is included.

  15. #15
    Registered User
    Join Date
    Jan 2009
    Location
    Australia
    Posts
    375
    Main should be declared as int main( void ).

    You don't need to be using conio. The screen doesn't need to be cleared at the beginning, and getchar can be used instead of getch.

    I think the problem you're trying to get at is that your variables aren't large enough to hold bigger factorials. You should declare your result variable as a larger type (and they need not be floating point types) such as long long int. You'll need to edit some of your input/output calls but that can easily be done by looking at the documentation.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Number Guessing
    By blacknapalm in forum C Programming
    Replies: 2
    Last Post: 10-01-2008, 02:48 AM
  2. To generate bar code from a number
    By darkducke in forum C Programming
    Replies: 18
    Last Post: 01-16-2008, 06:33 AM
  3. adding a number to a number
    By bigmac(rexdale) in forum C Programming
    Replies: 11
    Last Post: 10-24-2007, 01:56 PM
  4. Resource ICONs
    By gbaker in forum Windows Programming
    Replies: 4
    Last Post: 12-15-2003, 07:18 AM
  5. Replies: 25
    Last Post: 10-28-2001, 01:08 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21