[Dev-C++] numerical error in a simple program
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Luís B. <lf...@ya...> - 2003-09-03 08:17:05
|
When I try to compile this program:
********************************************
#include <stdio.h> // printf
#include <stdlib.h> // system
int main(int argc, char *argv[])
{
double a;
a = 0.3333;
printf( " a = %15.15f\n", a );
a *= 10;
printf( " a = %15.15f\n", a );
a *= 10;
printf( " a = %15.15f\n", a );
a *= 10;
printf( " a = %15.15f\n", a );
a *= 10;
printf( " a = %15.15f\n", a );
system("PAUSE");
return 0;
}
********************************************
I get this output:
********************************************
a = 0.333300000000000
a = 3.333000000000000
a = 33.329999999999998
a = 333.299999999999950
a = 3332.999999999999500
********************************************
How to avoid this error?
Thank in advance for any response.
=====
+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
Luís Filipe Delgado Brás
Eng.º Civil
Porto - Portugal
email: lf...@ya...
http://www.fotopt.net/autor.asp?autor=2637
+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com
|