Advertisement
link186fr

Decimales

Dec 29th, 2014
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.35 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int decimales;
  5. float numero;
  6. char cad[256];
  7.  
  8. int main()
  9. {
  10.     printf("Numero a leer: ");
  11.     scanf("%f", &numero);
  12.    
  13.     printf("Cuantos decimales: ");
  14.     scanf("%d", &decimales);
  15.     sprintf(cad, "%%.%df\n", decimales);
  16.    
  17.     printf(cad, numero);
  18.  
  19.     system("pause");
  20.     return 0;
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement