12345678910111213
#include <cstdio> #include <iostream> #include <iomanip> int main() { float cuzin = 5 ; std::printf( "%5.3f %20.3f\n", cuzin, cuzin ); std::cout << std::fixed << std::setprecision(3) << std::setw(5) << cuzin << ' ' << std::setw(20) << cuzin << '\n' ; }
123456789101112131415161718192021222324252627282930313233
#include <cstdio> #include <iostream> #include <iomanip> #include <cstdint> #include <cinttypes> int main() { float cuzin = 5 ; int precision ; std::uint32_t value ; { std::scanf( "%d", &precision ) ; char format[128] ; std::sprintf( format, "%%5.%df %%20.%df\n", precision, precision ) ; std::printf( format, cuzin, cuzin ); std::scanf( "%" SCNu32, &value ) ; std::printf( "%" PRIu32 "\n", value ) ; } { std::cin >> precision ; std::cout << std::fixed << std::setprecision(precision) << std::setw(5) << cuzin << ' ' << std::setw(20) << cuzin << '\n' ; std::cin >> value ; std::cout << value << '\n' ; } }