/* testfmt01.cpp CIS 150 6/16/2005 David Klick Demonstration of printf. */ #include int main(void) { int n = 1234567; double x = 1234.5678; char c = 'W'; char* msg = "Hello, world!"; printf("printf formatting demonstration\n\n"); printf("n = %d\nx = %f\n", n, x); printf("12345678901234567890\n"); printf("%10d\n", n); printf("%010d\n", n); printf("%-10d\n", n); printf("%+10d\n", n); printf("%5d\n", n); printf("%X\n", n); printf("%o\n", n); printf("%12.3f\n", x); printf("%.2f\n", x); printf("The char value is '%c'\nMy message is: %s\n", c, msg); printf("%s\n", msg); printf("%.9s\n", msg); return 0; } /* Sample output: printf formatting demonstration n = 1234567 x = 1234.567800 12345678901234567890 1234567 0001234567 1234567 +1234567 1234567 12D687 4553207 1234.568 1234.57 The char value is 'W' My message is: Hello, world! Hello, world! Hello, wo */