
Write a printf or scanf statement for each of the following:
- Print unsigned integer 40000 left justified in a 15-digit field with 8 digits.
- Read a hexadecimal value into variable hex.
- Print 200 with and without a sign.
- Print 100 in hexadecimal form preceded by 0x.
- Read characters into array s until the letter p is encountered.
- Print 1.234 in a 9-digit field with preceding zeros.
- 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.
- 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.
- 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.

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.

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.

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.

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.

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.

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.

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.

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.

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?
Chapter 9 Solutions
C How to Program (8th Edition)
Additional Engineering Textbook Solutions
Web Development and Design Foundations with HTML5 (8th Edition)
SURVEY OF OPERATING SYSTEMS
Introduction To Programming Using Visual Basic (11th Edition)
Starting Out With Visual Basic (8th Edition)
Computer Science: An Overview (13th Edition) (What's New in Computer Science)
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
- I need to resolve the following....You are trying to convince your boss that your company needs to invest in a license for MS-Project (project management software from Microsoft) before beginning a systems project. What arguments would you give her?arrow_forwardWhat are the four types of feasibility? what is the issues addressed by each feasibility component.arrow_forwardI would like to get ab example of a situation where Agile Methods might be preferable versus the traditional SDLC? What are the characteristics of this situation that give Agile Methods an advantage?arrow_forward
- What is a functional decomposition diagram? what is a good example of a high level task being broken down into tasks in at least two lower levels (three levels in all).arrow_forwardWhat are the advantages to using a Sytems Analysis and Design model like the SDLC vs. other approaches?arrow_forward3. Problem Description: Define the Circle2D class that contains: Two double data fields named x and y that specify the center of the circle with get methods. • A data field radius with a get method. • A no-arg constructor that creates a default circle with (0, 0) for (x, y) and 1 for radius. • A constructor that creates a circle with the specified x, y, and radius. • A method getArea() that returns the area of the circle. • A method getPerimeter() that returns the perimeter of the circle. • • • A method contains(double x, double y) that returns true if the specified point (x, y) is inside this circle. See Figure (a). A method contains(Circle2D circle) that returns true if the specified circle is inside this circle. See Figure (b). A method overlaps (Circle2D circle) that returns true if the specified circle overlaps with this circle. See the figure below. р O со (a) (b) (c)< Figure (a) A point is inside the circle. (b) A circle is inside another circle. (c) A circle overlaps another…arrow_forward
- 1. Explain in detail with examples each of the following fundamental security design principles: economy of mechanism, fail-safe default, complete mediation, open design, separation of privilege, least privilege, least common mechanism, psychological acceptability, isolation, encapsulation, modularity, layering, and least astonishment.arrow_forwardSecurity in general means the protection of an asset. In the context of computer and network security, explore and explain what assets must be protected within an online university. What the threats are to the security of these assets, and what countermeasures are available to mitigate and protect the organization from such threats. For each of the assets you identify, assign an impact level (low, moderate, or high) for the loss of confidentiality, availability, and integrity. Justify your answers.arrow_forwardPlease include comments and docs comments on the program. The two other classes are Attraction and Entertainment.arrow_forward
- Object-Oriented Programming In this separate files. ent, you'll need to build and run a small Zoo in Lennoxville. All classes must be created in Animal (5) First, start by building a class that describes an Animal at a Zoo. It should have one private instance variable for the name of the animal, and one for its hunger status (fed or hungry). Add methods for setting and getting the hunger satus variable, along with a getter for the name. Consider how these should be named for code clarity. For instance, using a method called hungry () to make the animal hungry could be used as a setter for the hunger field. The same logic could be applied to when it's being fed: public void feed () { this.fed = true; Furthermore, the getter for the fed variable could be named is Fed as it is more descriptive about what it answers when compared to get Fed. Keep this technique in mind for future class designs. Zoo (10) Now we have the animals designed and ready for building a little Zoo! Build a class…arrow_forward1.[30 pts] Answer the following questions: a. [10 pts] Write a Boolean equation in sum-of-products canonical form for the truth table shown below: A B C Y 0 0 0 1 0 0 1 0 0 1 0 0 0 1 1 0 1 0 0 1 1 0 1 0 1 1 0 1 1 1 1 0 a. [10 pts] Minimize the Boolean equation you obtained in (a). b. [10 pts] Implement, using Logisim, the simplified logic circuit. Include an image of the circuit in your report. 2. [20 pts] Student A B will enjoy his picnic on sunny days that have no ants. He will also enjoy his picnic any day he sees a hummingbird, as well as on days where there are ants and ladybugs. a. Write a Boolean equation for his enjoyment (E) in terms of sun (S), ants (A), hummingbirds (H), and ladybugs (L). b. Implement in Logisim, the logic circuit of E function. Use the Circuit Analysis tool in Logisim to view the expression, include an image of the expression generated by Logisim in your report. 3.[20 pts] Find the minimum equivalent circuit for the one shown below (show your work): DAB C…arrow_forwardWhen using functions in python, it allows us tto create procedural abstractioons in our programs. What are 5 major benefits of using a procedural abstraction in python?arrow_forward
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrC++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningProgramming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:Cengage
- Microsoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTProgramming with Microsoft Visual Basic 2017Computer ScienceISBN:9781337102124Author:Diane ZakPublisher:Cengage Learning




