printf
To display text on the screen, use the printf function.
Here are some examples:
-
printf("hello!\n"); printf("hello!\n
");
-
printf("hello!"); printf("hello!
");
-
printf("f(%d) = %f\n", k, sqrt(k) );
-
printf("%5d %4.6%f\n", k, sqrt(k) );
Notes:
-
Display the string "hello!" on two separate
lines.
-
Display the string "hello!hello!" on one line.
-
If k = 2, this displays "f(2) = 1.4142". The
"%d" is a place holder for integers and "
%f" is a place holder for floating point numbers.
-
Prints k in a space 5 characters wide, then prints one
blank space, then prints the square root of k in with 4
spaces before the decimal point, 6 after it.