Sets a type double variable to 1.0/3.0 and a type float variable to 1.0/3.0. - C Data Type

C examples for Data Type:double

Introduction

Display each result three times:

  • showing four digits to the right of the decimal,
  • showing 12 digits to the right of the decimal,
  • showing 16 digits to the right of the decimal.

include float.h and display the FLT_DIG and DBL_DIG .

Demo Code

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

int main(void)  
{  /* w w w .  jav  a  2 s. c  o  m*/
    float ot_f = 1.0 / 3.0;  
    double ot_d = 1.0 / 3.0;  
    printf(" float values: ");  
    printf("%.4f %.12f %.16f\n", ot_f, ot_f, ot_f);  
    printf("double values: ");  
    printf("%.4f %.12f %.16f\n", ot_d, ot_d, ot_d);  
    printf("FLT_DIG: %d\n", FLT_DIG);  
    printf("DBL_DIG: %d\n", DBL_DIG);  
    return 0;  
}

Result


Related Tutorials