C How to Program (8th Edition)
C How to Program (8th Edition)
8th Edition
ISBN: 9780133976892
Author: Paul J. Deitel, Harvey Deitel
Publisher: PEARSON
bartleby

Videos

Textbook Question
Book Icon
Chapter 9, Problem 9.4E

Write a printf or scanf statement for each of the following:

  1. Print unsigned integer 40000 left justified in a 15-digit field with 8 digits.
  2. Read a hexadecimal value into variable hex.
  3. Print 200 with and without a sign.
  4. Print 100 in hexadecimal form preceded by 0x.
  5. Read characters into array s until the letter p is encountered.
  6. Print 1.234 in a 9-digit field with preceding zeros.
  7. Read a time of the form hh:mm:ss, storing the parts of the time in the integer variables hour, minute and second. Skip the colons (:) in the input stream. Use the assignment suppression character.
  8. Read a string of the form “characters” from the standard input. Store the string in character array s. Eliminate the quotation marks from the input stream.
  9. Read a time of the form hh:mm:ss, storing the parts of the time in the integer variables hour, minute and second. Skip the colons (:) in the input stream. Do not use the assignment suppression character.

a.

Expert Solution
Check Mark
Program Plan Intro

To write a printf or scanf statement for given condition.

Explanation of Solution

Given information:

Print unsigned integer 40000 left justified in a 15-digit field with 8 digits.

Explanation:

Following is the print statement to print an unsigned integer 40000 left justified in a 15-digit field with 8 digits:

printf ( “%-15.8u”,40000 ) ;

The printf displays the given number as 8 digits with left justification in a l5 digit field.

  • -15 placed to the immediate right of % sign, is used to left justify the number and occupy 15 spaces.
  • Digit 8 after the decimal point places zeros to the left of the number to make it an 8-digit number.
  • Conversion specifier u is used to print unsigned numbers.

b.

Expert Solution
Check Mark
Program Plan Intro

To write a printf or scanf statement for given condition.

Explanation of Solution

Given information:

Read a hexadecimal value into variable hex.

Explanation:

Following is the scanf statement to read a hexadecimal value into hex variable:

scanf ( “%x”, hex ) ;

The scanf statement inputs a hexadecimal number in the variable named hex using conversion specifier %x.

c.

Expert Solution
Check Mark
Program Plan Intro

To write a printf or scanf statement for given condition.

Explanation of Solution

Given information:

Print 200 with and without a sign.

Explanation:

Following is the printf statement to print 200 with and without a sign:

printf ( “%+d\n %d\n”, 200, 200 ) ;

The printf statement prints the value 200, with and without a plus sign. If we place a + sign immediate to the right of %sign, then, a positive value is printed with a plus sign and a negative value is printed with a minus sign.

d.

Expert Solution
Check Mark
Program Plan Intro

To write a printf or scanf statement for given condition.

Explanation of Solution

Given information:

Print 100 in hexadecimal form preceded by 0x.

Explanation:

Following is the printf statement to print 100 in hexadecimal form preceded by 0x:

printf ( “%#x\n”, 100 ) ;

The printf statement is used to print 100 preceded by Ox. This is accomplished by using a # flag placed immediate to the right of % sign in the field.

e.

Expert Solution
Check Mark
Program Plan Intro

To write a printf or scanf statement for given condition.

Explanation of Solution

Given information:

Read characters into arrays s until the letter p is encountered.

Explanation:

Following is the scanf statement to read characters into arrays s until the letter p is encountered:

scanf ( “%[^p]”, s ) ;

The scanf statement is used to read the string until the letter p appears. This is achieved by inverted scan set, that is, by placing a Caret (^) before the character.

f.

Expert Solution
Check Mark
Program Plan Intro

To write a printf or scanf statement for given condition.

Explanation of Solution

Given information:

Print 1.234 in a 9-digit field with preceding zeros.

Explanation:

Following is the printf statement to print 1.234 in a 9-digit field with preceding zeros:

printf ( “%09.3f\n”, 1.234 ) ;

The printf statement prints the given floating-point number in the field of 9 digits and preceded by zeros. Thus achieved by placing 09 immediate to the right of % sign.

Digit 3 after the decimal point is used to provide precision up to 3 values.

g.

Expert Solution
Check Mark
Program Plan Intro

To write a printf or scanf statement for the given condition.

Explanation of Solution

Given information:

Write time of the hh: mm: ss type, storing the timepieces in the hour, minute and second integer variables. Skip the colons (:) through the input tube. Use the character assignment Suppression.

Explanation:

Following is the scanf statement to read the time in form hh:mm:ss -:

scanf ( “%d*c%d*c%d”, &hour, &minute, &second ) ;

The scanf statement is used to input the time in the form hh:mm:ss. The colons (:) are eliminated using the suppression character (*) in the field.

h.

Expert Solution
Check Mark
Program Plan Intro

To write a printf or scanf statement for given condition.

Explanation of Solution

Given information:

Read a string from the standard input of the "characters" type. Place the string in character array s. Eliminate quotation marks from the input stream.

Explanation:

Following is the scanf statement to read a string of characters and store in array s -:

scanf ( “\”%[^\“]”, s ) ;

The scanf statement is used to input a string by the in quotation marks in a character array, s, and eliminate those quotation marks.

This is achieved by using an inverted scan set where a caret (^) before the \” sign is placed.

i.

Expert Solution
Check Mark
Program Plan Intro

To write a printf or scanf statement for given condition.

Explanation of Solution

Given information:

Read a time of type hh: mm: ss, storing time pieces in the hour, minute and second integer variables. Skip the input stream colons (:). Do not use the character Assignment Suppression.

Explanation:

Following is the scanf statement to read the time in form hh:mm:ss and skip the colons without using assignment suppression character -:

scanf ( “%d:%d:%d: ”, &hour, &minute, &second ) ;

The scanf statement is used to input the time in the form hh:mm:ss. The colons (:) are eliminated by placing colons (:) in the scanf statement as shown, if we do not have to put suppression character.

Want to see more full solutions like this?

Subscribe now to access step-by-step solutions to millions of textbook problems written by subject matter experts!
Students have asked these similar questions
Trace these print statements using the following arrays. Write "error", if an error occurs.
2. Printing binary Write a function void printBin(int value) that will print an integer as a binary number. Hint: You want to print a 1 or a O based on the high order bit, then you need to move the next to high order bit into the high order bit. You will need to explicitly count the number of bits you have printed. Write a main method that calls printBin multiple times with a few different values to test it. You should try at least a positive number, a negative number and O. Your submission should answer the following questions about this program: • There are at least two approaches to testing the high order bit. Describe one that you did NOT use in your code. • How could you suppress leading zeros in you display? If you did this already, you may just answer that you did.
Create a program and flowchart for the following: Write a program that inputs the value 437 five times(use an array here) using each of the scanf conversion specifiers: %s,%d,%i, %o,%u, and %x. Print each input value using all integer conversion specifiers.
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Program to find HCF & LCM of two numbers in C | #6 Coding Bytes; Author: FACE Prep;https://www.youtube.com/watch?v=mZA3cdalYN4;License: Standard YouTube License, CC-BY