#include <stdio.h>
#include <stdlib.h>
int main( void )
{
/* Ajuste de alinhamento
*/
printf ( "Alinhamento dos valores impressos:\n " ) ; printf ( "Esquerda : %-5d \n " , 10 ) ; printf ( "Direita : %5d \n " , 10 ) ; printf ( "Zeros a esquerda : %05d \n \n " , 10 ) ;
/* Impressao de valores com ajuste de precisao
(note o arredondamento)
*/
float val = 14.8317 ;
printf ( "Ajuste da precisao dos valores impressos (note o arredondamento):\n " ) ; printf ( "Valor %.4f com 2 casas de precisao: %.2f \n " , val
, val
) ; printf ( "Valor %.4f com 3 casas de precisao: %.3f \n " , val
, val
) ;
/* Cinco casas decimais sao acrescidas.
Note que prevalece o maior valor entre os campos tamanho / precisao.
*/
printf ( "Valor: %9.8f \n \n " , 120.153 ) ;
/* O limite de precisao da linguagem C eh aquele do formato double:
52 bits da fracao + 1 bit da parte inteira implicita = 53 bits
53 bits * log(2) = 15.9545 -> aprox. 16 digitos decimais
*/
float z1 = 1.1234567890123456789 ;
double z2 = 0.1234567890123456789 ;
printf ( "Limites do grau de precisao:\n " ) ; printf ( "Limite de precisao (float) : %.30lf \n " , z1
) ; printf ( "Limite de precisao (double): %.30lf \n " , z2
) ; printf ( "Limite de precisao (const) : %.30lf \n " , 1.1234567890123456789 ) ;
printf ( "Impar: %#.0f \n " , 3.5 ) ; printf ( "Par : %#.0f \n " , 2.5 ) ;
return 0 ;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KCmludCBtYWluKHZvaWQpCnsKCS8qIEFqdXN0ZSBkZSBhbGluaGFtZW50byAKICAgICovCglwcmludGYoIkFsaW5oYW1lbnRvIGRvcyB2YWxvcmVzIGltcHJlc3NvczpcbiIpOwoJcHJpbnRmKCJFc3F1ZXJkYSAgICAgICAgIDogJS01ZCBcbiIsIDEwKTsKCXByaW50ZigiRGlyZWl0YSAgICAgICAgICA6ICU1ZCBcbiIsIDEwKTsKCXByaW50ZigiWmVyb3MgYSBlc3F1ZXJkY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