/* * Selftest1 * Chapter 5 * John Stile */ 1. Correct errors in each statemnt if any Original: Correction: 1a. printf("%s\n", 'hello'); // perfect 1b. printf("%s\n", &str); printf("%s\n", str); 1c. printf("%f\n", 3); printf("%f\n", (float)3); 1d. printf("%c\n", "t"); // perfect 2. What does the following code accomplish. Explain how it works // When the input is t, it echos t three times, with new line after each while ( (xx=getchar()) != "t" ) // get a char from input buffer // store in address of variable xx // test if xx contains the letter t // if true do what is in the while loop { putchar(xx); // put letter t in stdout (terminal) putchar(xx); // put letter t in stdout (terminal) putchar(xx); // put letter t in stdout (terminal) } 3. What is the following printf instruction accomplishing? printf("%-15s%12.3d%10.2f", "C Language", 27, 1.5); // %-15s - left justify the string "C Language by 15 spaces, print "C Language" // %12.3d - right pad with 12 spaces before decimal, use precision of 3 digits, so print "027" // %10.2f - right pad with 10 spaces before decimal, use precision of 2 digits, so print "1.50" 4. Write a short program wich outputs the following text using printf: How do you print %d, %f, %s "as they are"? /* * program to print: How do you print %d, %f, %s "as they are"? */ #include int main(void) { printf("How do you print %%d, %%f, %%s \"as they are\"\?\n"); return 0; }