READ: Function printf The C Programming Language
§ 7.2 pp 125-6
Hello, world!on the screen. The last character printed by function printf is the newline character ('\n'). That causes a movement down one line and back to the left. The next print will start in the line directly below Hello, world! right under the H.
There are three arguments separated by commas:printf("This is program %d its my %s!\n", 6+4, "tenth");
What will be printed is the first string but with substitutions for %d and %s. %d and %s are conversion specifications. They control how the other arguments will be converted to characters that are put into the first argument. The %d specification requires that the value of the argument corresponding to it (argument: 6+4; value: 10) be an int and that the specification will be replaced by decimal digits corresponding to the value. So a '1' followed by '0' is put in place of %d. If the specification had been %o, the int 10 would have been converted to octal digits: a '1' followed by '2' and that would have been put in place of the %o. The %s specification requires that that the argument corresponding to it (the "tenth") be a string. The characters of the string are put in place of the %s."This is program %d its my %s!\n" 6+4 "tenth"
%5s %5.2f %.2f %5.2dThe number before the decimal point (or if there is no decimal point) is the minimum field width. You are guarateed that the correspoinding argument will be printed in a field of at least that size. If the argument is small, it will be padded by blanks of zeros. The number coming after the decimal point is the precision. If the argument is a string, the precision is the maximum number of characters to be printed. If the argument is an int, it is the minimum number of digits to be printed If the argument is floating point, it is the number of digits to be printed after the decimal point.
Next: Homework 01