Author Topic: C Double Float and printf problem  (Read 6678 times)

SlyVixsky

  • Guest
C Double Float and printf problem
« on: July 31, 2009, 12:46:32 am »
Windows and GCC

I am trying to run the fibonacci sequence via the following code:

#include <stdio.h>
#include <float.h>

int main()
{
  float x;
  float y;
  int lim44;
  printf( "Enter the number of cycles: ");
  scanf( "%d", &lim44);

  x = 1.0;
  y = 1.0;

  do {
    /* "Hello, world!" is printed at least one time
      even though the condition is false*/
    printf( "%32.1Lf\n", x );
    x = x+y;
    lim44 = lim44-1;
    printf( "%32.1Lf\n", y);
    y = y+x;
    lim44 = lim44-1;
  } while ( lim44 > 0 );
  getchar();
}

However, it outputs zeros after the first 16 digits, making the results inaccurate. I have used double, as well as long long type settings, with the same results in that i cannot even achieve the 100th iteration without the output failing.  Does anyone have any advice?

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7256
Re: C Double Float and printf problem
« Reply #1 on: July 31, 2009, 12:49:05 am »
Yes, ask in a C/C++ related forum, not in the C::B-forum.
This forum is dedicated to C::B an IDE not a compiler.

Topic is unrelated to C::B, so it gets locked !