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
Computer Science: An Overview (12th Edition)
Problem Solving with C++ (9th Edition)
Starting Out with C++ from Control Structures to Objects (9th Edition)
Software Engineering (10th Edition)
Starting Out with Python (3rd Edition)
Java How To Program (Early Objects)
- (Practice) Write array declarations for the following: a. A list of 100 double-precision voltages b. A list of 50 double-precision temperatures c. A list of 30 characters, each representing a code d. A list of 100 integer years e. A list of 32 double-precision velocities f. A list of 1000 double-precision distances g. A list of 6 integer code numbersarrow_forward(Practice) a. Write output statements using cout that can be used to display values from the first, third, and seventh elements of each array declared in Exercise 2. b. Write a for loop that can be used to display values for the complete array declared in Exercise 2.arrow_forward(Numerical) Write a program that tests the effectiveness of the rand() library function. Start by initializing 10 counters to 0, and then generate a large number of pseudorandom integers between 0 and 9. Each time a 0 occurs, increment the variable you have designated as the zero counter; when a 1 occurs, increment the counter variable that’s keeping count of the 1s that occur; and so on. Finally, display the number of 0s, 1s, 2s, and so on that occurred and the percentage of the time they occurred.arrow_forward
- 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 is150arrow_forwardType 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…arrow_forwardTask: A shop sells a range of mobile devices, SIM cards and accessories as shown in the table (see screenshot): Write a program algorithm for this shop. - Your program or programs must include appropriate prompts for the entry of data; data must be validated on entry. - Error messages and other output need to be set out clearly and understandably. - All arrays, variables, constants and other identifiers must have meaningful names. You will need to complete these three tasks. Task 1 – Setting up the system. Write a program to: - use appropriate data structures to store the item code, description and price information for the mobile devices, SIM cards and accessories; - allow the customer to choose a specific phone or tablet; - allow phone customers to choose whether the phone will be SIM Free or Pay As You Go; - allow the customer to choose a standard or luxury case; - allow the customer to choose the chargers required (none,…arrow_forward
- 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.arrow_forwardWrite a C program with two separate functions to determine 3 people' average score and highest score for user given data. Use array size of 5 to store marks and pass array to two separate functions for the average and highest score. (Note: the use of flag and bool is not allowed)The program output should look like this:Enter person 1’s Name: AvyaanEnglish score: 50Math score: 75Spanish score: 60Enter person 2's Name : Advik....Name : AvyaanHighest Score : 75Average Score : 61.6arrow_forwardCreate a program and flowchart for the following: Write a program that uses random-number generation to create sentences. The program should use four arrays of pointers to char called article, noun, verb and preposition. The program should create a sentence by selecting a word at random from each array in the following order: article, noun, verb, preposition, article and noun. As each word is picked, it should be concatenated to the previous words in an array large enough to hold the entire sentence. The words should be separated by spaces. When the final sentence is output, it should start with a capital letter and end with a period. The program should generate 20 such sentences. The arrays should be filled as follows: The article array should contain the articles "the", "a", "one", "some" and "any"; the noun array should contain the nouns "boy", "girl", "dog", "town" and "car"; the verb array should contain the verbs "drove", "jumped", "ran", "walked" and "skipped"; the preposition…arrow_forward
- Which of the following arithmetic operations may be performed on struct variables but not on array variables?arrow_forward1) Write a C++ program to allow the user to enter the score of 8 courses andstore them in an array.Then display the scores.Count how many students their scores are greater than 60 , then print Pass.Count how many students their scores less than 60 then print Fail (using aloop over the array elements) based on the following output sample. Output:Enter 8 values of scores: 90 65 49 70 55 88 73 50The scores are: 90 65 49 70 55 88 73 50The total number of students whose scores greater than 60: 5PassThe total number of students whose scores less than 60: 3Failarrow_forwardWRITE C++ PROGRAM: Typhoon Casualties. Write a program using arrays to enter the following data: names of victims of typhoon Odette, age, and condition (A – alive, D – deceased, I – injured and M – missing). The size of your arrays should match the estimated number of persons in that particular barangay. Enter the name of barangay and the estimated total number of persons residing in that barangay during the typhoon. Display the following after the data entry according to their names – name (alphabetical order), condition and the count of person(s) alive, deceased, injured and missing and then get their percentage from the total population. Earthquake Incident Name of Barangay: _____________ Estimated number of residents:________ Name:____ Age:__ Condition (A,D,I or M):___ More Entry (Y/N)? Y Name:____ Age:____ Condition (A,D,I or M):___ : : Name:____ Age:____ Condition (A,D,I or M):___ More Entry (Y/N)? N List of Victims/Casualties Name Age Condition _____…arrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningC++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr