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
(Write C++ Statements) Write a statement for each of the following:a) Print integer 40000 left justified in a 15-digit field.b) Read a string into character array variable state.c) Print 200 with and without a sign.d) Print the decimal value 100 in hexadecimal form preceded by 0x.e) Read characters into array charArray until the character 'p' is encountered, up to a limit of 10 characters (including the terminating null character). Extract the delimiter fromthe input stream, and discard it.f) Print 1.234 in a 9-digit field with preceding zeros.
Consider a two-by-three integer array t. a)  Write a statement that declares and creates t.b)  How many rows does t have? c)  How many columns does t have? d)  How many elements does t have? e)  Write access expressions for all the elements in row 1 of t. f)  Write access expressions for all the elements in column 2 of t. g)  Write a single statement that sets the element of t in row 0 and column 1 to zero. h)  Write a series of statements that initializes each element of t to zero. Do not use a repetition statement. i)  Write a nested for statement that initializes each element of t to zero.j)  Write a nested for statement that inputs the values for the elements of t from the user. k)  Write a series of statements that determines and displays the smallest value in t. l)  Write a printf statement that displays the elements of the first row of t. Do not use repetition. m)  Write a statement that totals the elements of the third column of t. Do not use repetition. n)  Write a series of…
C++ this is the code i am having the following error in the png   #include <iostream>#include <iomanip>#include <cctype>#include <string.h> using namespace std; // Global constantsconst int MaxWordSize = 81; // 80 characters + 1 for NULL // Given an array of characters and a shift value:// shift each character in the original text by some amount,// storing the result into the shiftedText array.// Remember: Wrap around at the end of the alphabet.// *** In the line below you must supply the function// return type and the parameter(s) ***void shiftTheText(char startingText[], int shiftVal, char shiftedText[]){// Loop through each character in the C string, startingText// When the character is an alphabetic character,// shift it by adding the shift value.// Then store the resulting character in its proper spot// in the shiftedText C string.size_t a = strlen(startingText);for(int i=0; i<a; i++){int temp =…
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
Text book image
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
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