Answers for Day 7
Quiz
- There are two differences between puts()andprintf():
printf()can print variable parameters.
puts()automatically adds a newline character to the end of the string it prints. - You should include the stdio.h header file when using printf().
- a.\prints a backslash.
b.\bprints a backspace.
c.\nprints a newline.
d.\tprints a tab.
e.\a(for “alert”) sounds the beep. - a.%sfor a character string
b.%dfor a signed decimal integer
c.%ffor a decimal floating-point number - a.bprints the literal character b.
b.\bprints a backspace character.
c.\looks at the next character to determine an escape character (see Table 7.1).
d.\prints a single backslash.
Exercises
1.puts()automatically adds the newline; printf()does not. The code is as follows:
printf( “\n” );
puts( “ “ );
- The code is as follows:
char c1, c2;
int d1;
scanf( “%c %ud %c”, &c1, &d1, &c2 ); - Your answer might vary:
#include <stdio.h>
int x;
int main( void )
{
puts( “Enter an integer value” );
842 Appendix F
49 448201x-APP F 8/13/02 11:22 AM Page 842