Computes the accuracy of the floating point numbers in storage and calculations : Float « Data Type « C / ANSI-C






Computes the accuracy of the floating point numbers in storage and calculations

#include <stdio.h>
int main()
{
    float floatNumber1, floatNumber2;
    float result;
    int   counter;

    floatNumber1 = 1.0;
    floatNumber2 = 1.0;
    counter = 0;

    while (floatNumber1 + floatNumber2 != floatNumber1) {
        ++counter;
        floatNumber2 = floatNumber2 / 10.0;
    }
    printf("%2d digits accuracy in calculations\n", counter);

    floatNumber2 = 1.0;
    counter = 0;

    while (1) {
        result = floatNumber1 + floatNumber2;
        if (result == floatNumber1)
            break;
        ++counter;
        floatNumber2 = floatNumber2 / 10.0;
    }
    printf("%2d digits accuracy in storage\n", counter);
    return (0);
}


           
       








Related examples in the same category

1.Floating Point Input
2.Read user input: float
3.Calculation: float
4.Average the items in a 5 element array
5.Use float as for loop control variable
6.Print i and i/2 with fractions
7.Work with int and float
8.Output float
9.Calculation between int and float
10.Use scanf and printf to read and write float value in console
11.Do calculation in printf: float value
12.Working with float
13.Save calculation result into a float variable