C/printf: Różnice pomiędzy wersjami
Usunięta treść Dodana treść
m →Zobacz też: float.h |
m →zmienny format: nowy kod |
||
Linia 380:
}
</source>
====Liczba cyfr ====
<source lang=c>
/*
https://www.digitalmars.com/ctg/ctgNumerics.html
gcc f.c -lm -Wall
./a.out
*/
#include <stdio.h>
#include <float.h>
#define pi 3.14159265358979323846264338327950288419716939937510582097494459230781 // https://pl.wikipedia.org/wiki/Pi
int main()
{
long double l;
double d;
float f;
l = (long double) pi;
printf("(long double) \tpi = %.*Lg\n", LDBL_DIG, l);
d = (double)pi;
printf("(double) \tpi = %.*g\n", DBL_DIG, d);
f = (float) pi;
printf("(float) \tpi = %.*g\n", FLT_DIG, f);
return 0;
}
</source>
Wynik:
<source lang=bash>
(long double) pi = 3.14159265358979312
(double) pi = 3.14159265358979
(float) pi = 3.14159
</source>
====fragment łańcucha ( ang. substring)====
|