Thread: Factorial with decimals

  1. #1
    Registered User
    Join Date
    May 2011
    Posts
    8

    Factorial with decimals

    I'm trying to write a factorial for these numbers 1.1+2.2+3.3+4.4+5.5 to infinity.

    I thought I'd try with one number and then using recursion to go to infinity.
    However I seem to be having a problem trying to get it. It just flashes whenever i run the program. I'm using codeblocks

    Code:
        
    double i;
    double num = 1.2;
    double j=1;
    
    for (i=1; i<num; i+.1){
       j=j*i;
    }
    
    printf("The factorial of %lf is %lf\n",num,j);
    Should I use a while loop instead?

  2. #2
    Awesomefaceradcore bivhitscar's Avatar
    Join Date
    Apr 2006
    Location
    Melbourne, Australia
    Posts
    210
    Does code::blocks detect infinite loops? Because that's what you've got there.

    Code:
    for (i=1; i<num; i+=.1){
       j=j*i;
    }
    it's ironic considerate rarity patron of love higher knowledge engulfs me...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Decimals in C++
    By slimdime in forum C++ Programming
    Replies: 2
    Last Post: 09-03-2010, 10:23 AM
  2. decimals to hex
    By rajkumarmadhani in forum C Programming
    Replies: 2
    Last Post: 08-08-2007, 11:29 AM
  3. allow decimals
    By dankassdann in forum C++ Programming
    Replies: 3
    Last Post: 10-28-2006, 06:41 PM
  4. Getting enough decimals
    By Drogin in forum C++ Programming
    Replies: 3
    Last Post: 10-29-2005, 09:37 PM
  5. decimals
    By RyeDunn in forum C++ Programming
    Replies: 13
    Last Post: 07-15-2002, 01:37 AM