Advertisement
LinguagemC

FormatandoAsaida

Aug 24th, 2016
1,307
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <windows.h>
  5. #include <conio.h>
  6. using namespace std;
  7. // A furmacao dos tipos e endicada logo apos  %  e antes do campo do tipo
  8. int main(){
  9.  
  10. //Codigo                  Formatacao
  11.  
  12. printf("%4d", 45);// No minimo 4 caracteres
  13. cout<<endl;
  14. printf("%-4d", 45);// Anterior, mas alinhado a esc7
  15. cout<<endl;
  16. printf("%04d", 45);// Completa com zeros
  17. cout<<endl;
  18. printf("%.2f", 75.777);// 2 Casas decimais
  19. cout<<endl;
  20. cout<<endl;
  21. cout<<endl;
  22. printf("%8.2f", 75.777);// Anterior, mas com 8 caracteres
  23. cout<<endl;
  24. cout<<endl;
  25. cout<<endl;
  26. printf("%-8.2f", 75.777); // Anterior, mas alinhado a esc
  27.  
  28.  return 0;
  29.  system("pause>null");
  30. }
Advertisement
RAW Paste Data Copied
Advertisement