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.
Using C++ Input a number into an array of characters.  Check to see if all of the characters in the array are numeric.  If they are not all numeric output (invalid input).  If they are all numeric convert the characters to there integer form.  Once in the integer form add 25 to the integer and print it out. Example run:Input a number-> 12A3(Invalid input)Input a number->125Your number plus 25 is150
Type C Programming: Write a program that: Declare the following integer variables: - Leftmotor - Rightmotor Declare the following character arrays: - lilac of size 50. - lea of size 30. Repeat the steps below 10 times and then quit the program. Ask the user for a robot command and store it in a character array of size 50. Store the user input in lilac. The user input consist of up to two words inputted as one string. The motors are assigned values according to the string input and the table below. Also the input string could be one word or two words. If the first word is STOP then no further instruction is needed (no second word in the string). If the first word is move then a second word will follow First word Second word Left motor Right motor STOP 0 0 MOVE FORWARD 127 127 MOVE REVERSE -127 -127 MOVE LEFT 64 127 MOVE RIGHT 127 64 The user input could be a mix of upper case and lower case letters so you need to change all the input to upper case before comparing with the…
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