Curso de Programación en C/Prog20

De WikiCabal
< Curso de Programación en C
Revisión del 21:16 11 jun 2012 de Archanasingh (discusión | contribuciones) (Resultado)
(dif) ← Revisión anterior | Revisión actual (dif) | Revisión siguiente → (dif)
Ir a la navegación Ir a la búsqueda

Prog20

 1 /* Prog20.c -- Conversiones interesantes con floats */
 2 
 3 #include <stdio.h>
 4 
 5 int main( void )
 6 {
 7   float  n1 = 3.0;
 8   double n2 = 3.0;
 9   long   n3 = 2000000000,
10          n4 = 1234567890;
11 
12   printf( "Con conversiones naturales: %f %lf    %ld %ld\n", n1, n2, n3, n4 );
13   printf( "Con %%.1e:                   %.1e  %.1e     %.1e    %.1e\n",
14                                                              n1, n2, n3, n4 );
15   printf( "Con %%ld:                    %ld        %ld  %ld          %ld\n",
16                                                              n1, n2, n3, n4 );
17 
18   return 0;
19 }

Resultado

[rrc@Pridd CClase]$ gcc -Wall -O2 -o Prog20 Prog20.c
Prog20.c: In function ‘main’:
Prog20.c:14: warning: format ‘%.1e’ expects type ‘double’, but argument 4 has type ‘long int’
Prog20.c:14: warning: format ‘%.1e’ expects type ‘double’, but argument 5 has type ‘long int’
Prog20.c:16: warning: format ‘%ld’ expects type ‘long int’, but argument 2 has type ‘double’
Prog20.c:16: warning: format ‘%ld’ expects type ‘long int’, but argument 3 has type ‘double’
[rrc@Pridd CClase]$ ./Prog20
Con conversiones naturales: 3.000000 3.000000    2000000000 1234567890
Con %.1e:                   3.0e+00  3.0e+00     3.1e+46    6.6e-316
Con %ld:                    0        1074266112  0          1074266112
[rrc@Pridd CClase]$

Explicación