I l @ ve RuBoard |
Run Listing 4.1 again, but this time give your first and last name when it asks you for your first name . What happens? Why?
Assuming that each of the following examples is part of a complete program, what will each one print?
printf("He sold the painting for $%2.2f.\n", 2.345e2);
printf("%c%c%c\n", 'H', 105, '');
#define Q "His Hamlet was funny without being vulgar." printf("%s\nhas %d characters.\n", Q, strlen(Q));
printf("Is %2.2e the same as %2.2f?\n", 1201.0, 1201.0);
In Question 2.c., what changes could you make so that string Q is printed out enclosed in quotes?
It's find the error time!
define B booboo define X 10 main(int) { int age; char name; printf("Please enter your first name."); scanf("%s", name); printf("All right, %c, what's your age?\n", name); scanf("%f", age); xp = age + X; printf("That's a %s! You must be at least %d.\n", B, xp); rerun 0; }
Suppose a program starts like this:
#define BOOK "War and Peace" int main(void) { float cost =12.99; float percent = 80.0;
Construct a printf() statement that uses BOOK , cost , and percent to print the following:
This copy of "War and Peace" sells for .99. That is 80% of list.
What conversion specification would you use to print each of the following?
A decimal integer with a field width equal to the number of digits ____________
A hexadecimal integer in the form 8A in a field width of 4 _____
A floating-point number in the form of 232.346 with a field width of 10 ______
A floating-point number in the form 2.33e+002 with a field width of 12 _____
A string left-justified in a field of width 30 _____
Which conversion specification would you use to print each of the following?
An unsigned long integer in a field width of 15.
A hexadecimal integer in the form 0x8a in a field width of 4.
A floating-point number in the form 2.33E+02 that is left-justified in a field width of 12.
A floating-point number in the form +232.346 in a field width of 10.
The first 8 characters of a string in a field 8 characters wide.
What conversion specification would you use to print each of the following?
A decimal integer having a minimum of 4 digits in a field width of 6 _____
An octal integer in a field whose width will be given in the argument list _____
A character in a field width of 2 ____
A floating-point number in the form +3.13 in a field width equal to the number of characters in the number.
The first 5 characters in a string left-justified in a field of width 7_____
For each of the following input lines, provide a scanf() statement to read it. Also declare any variables or arrays used in the statement.
101
22.32 and 8.34E-09
Chelsea
catch 22
catch 22 (but skip over catch)
What is whitespace?
Suppose that you would rather use parentheses than braces in your programs. How well would the following work?
#define ( { #define ) }
I l @ ve RuBoard |