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) 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) Using the srand() and rand() C++ library functions, fill an array of 1000 floating-point numbers with random numbers that have been scaled to the range 1 to 100. Then determine and display the number of random numbers having values between 1 and 50 and the number having values greater than 50. What do you expect the output counts to be?arrow_forwardThis code is in c. The question I have is that I have to find a min and maxes in arrays A and B. Based on source code and complied response below how can I fix my logical errors. Feel free to edit put notes about the source code. #include <stdio.h>#include <math.h>#include <stdlib.h>#define N 10 int main(void){ int i,j,k,n, max, min; float a[N], b[N],sum; char key_hit; do { printf("Please input how many values are inside array a (from 2 to 10):"); scanf("%i", &n); }while (n<2 || n>10); printf("\n\nPlease enter array a values"); for(i=1; i<=n; i+=1) { printf("\narray a value %i. : ",(i)); scanf("%f", &a[i]); } do { printf("Please input how many values are inside array b (from 2 to 10):"); scanf("%i", &k); }while (k<2 || k>10); printf("\n\nPlease enter array b values"); for(j=1; j<=k; j+=1) { printf("\narray…arrow_forward
- Question 1a. What digits are used in the binary number system?b.What digits are used in the decimal number system?c.What digits are used in the octal number system?d.What digits are used in the hexadecimal number system? \ Question 2In the following program, there is a call to the print_in_reverse function whichhas the following prototype: void print_in_reverse(float *a, int count); Using pointers, write this function to print the array in reverse order. #include <stdio.h>#define A_SIZE(A) sizeof(A)/sizeof(A[0]) void print_in_reverse(float a[], int count);int main(void) { float values[6] = { 12.1F, 22.2F, 32.3F, 42.4F, 52.5F, 62.6F }; printf("The array in reverse\n"); print_in_reverse(values, A_SIZE(values)); return 0;} Question 3The program below reads two integers. Then a function with the followingprototype is called: void div_rem(int a,…arrow_forward#include <stdio.h> int main(){ int arr[10]; int i; for (i=0; i<10; i++){ arr[i] = i; } for (i=0; i<10; i++){ printf("arr[%d] = %d\n", i, arr[i]); } return 0;} Copy the code and modify it as follows: Add another separate array of 10 integers. The following code parts are to be added (in the same order as specified) after the printing of the values of the first array:(1) Copy the content of the first array to the second array. Add 10 to each of the values of the second array. Make use of a single loop to achieve this part.(2) Print each element of the second array. Make use of another loop for this partarrow_forwardQuestion 1 Write the function “count” to count the number of lower-case letters in a character array. The size of the array is five. The ASCII table is shown below. #include int count(char input[], int size) { // Your Codes Here } int main(void) { char input[5]; for(int i = 0; i< 5; i++){ scanf("%c", &input[i]); } printf("%d\n", count(input, 5)); return 0; } input: ABCde output: 2 ...arrow_forward
- Q4: Write a program using funcions, write saperate functions for input and output, program should take input 10 numbers in an array, counts the zeros, even and odd numbers in array. Finally prints the total number of zeros, even and odd numbers.arrow_forwardWrite a short program that will request input from a user. 10 integers should be read from the user and stored in an array (in a procedure). The sum of the integers should be computed (in a procedure) and output with a message including what the numbers are and what the sum is (in a procedure). Does your program handle positive and negative integers? Can you quickly adapt your program to handle 8-, 16-, and 32-bit integers? Describe the process or why your code works for different data sizesarrow_forward1. single element of an array can be passed to the function? true or false. 2. Array can be declared as constant? true or false. 3. which of the following gives the memory address of the first element in array x? a. X b. X[0] c. X{0} d. X_0 e. X(0) 4. The index of the last element of array X whose size is S? a. S+1 b. S-1 c. 0 d.1000 e. S 5. Assume you have the following declarations const int MAX = 1000;double A[MAX];which of the following sentences is incorrect? a. The assingnment statement MAX = 1000 is mandatory. b. we can store up to 1000 values in the mandatory. c we cannot change the size of the array A during the runtime. d. all values in the array are set to ZERO's (0) e. all above sentences are correct. 6. The only difference between char array and string is that, the string ends with '\0'? true or false. 7. Index of an array can be of type integer or double, since both deals with the digits? True or False 8. Which definition describes the term Array precisely?…arrow_forward
- Write a program that asks the user to input a series of numbers. Theprogram should read the numbers into an array and then does the following:a) Write a function that will find the average value in the array.b) Write a function that will find the mode value in the array.c) Write a function that will display the sorted array of numbers from maximum tominimum.d) Write a function that will search the array for a specific value.e) Write a function that will display all of this information to the user in a nice format.You should submit the flowchart and the python code for this assignmentarrow_forwardStore an array of integers indicated by the constant variable SIZE and write a c++ code that checks if the array is stored in ascending order or not. The output should be the original array and the result.arrow_forwardGiven the following code and output:int a[] = {10, 20, 30, 40};cout << a << endl; Example Output3F70Answer the following questions in your own words:1. How much memory does each integer in the array use?2. How much memory does the entire array use?3. What is the memory address of the value 10?4. What is the memory address of the value 30?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 PtrProgramming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:Cengage