
A decimal point before the field width specification in a p statement has a special purpose. Try to determine its purpose by typing in and running the following
#
i
{
}

Explanation of Solution
Program:
The following program will display the decimal point before the field width specification:
//include the header file
#include <stdio.h>
//definition of main method
int main (void)
{
//declare the variables
int dollars, cents, count;
//check the condition
for (count = 1; count <= 10; ++count)
{
//get the input from the user
printf("Enter dollars: ");
scanf("%i", &dollars);
printf("Enter cents: ");
scanf("%i", ¢s);
//display the result
printf("$%i.%.2i\n\n", dollars, cents);
}
//return statement
return 0;
}
Explanation:
In the above program, declare the required header file. Inside the main method, declare the necessary variables. The “for” condition is used to get the 10 inputs from the user and print the result using field width specification. The “$%i.%.2i” in the print statement denotes the “$%i” is left side of the dot which means before the dot one numbers will appears and “%.2i” is right side of the dot which means after the dot two numbers will appears.
If the print statement is:
printf("$%.3i.%.5i\n\n", dollars, cents);
the “$%.3i” is left side of the dot which means before the dot three numbers will appears and “%.5i” is right side of the dot which means after the dot five numbers will appears. The output is: $006.00005
If the print statement is:
printf("$%.5i.%.10i\n\n", dollars, cents);
the “$%.5i” is left side of the dot which means before the dot five numbers will appears and “%.10i” is right side of the dot which means after the dot ten numbers will appears. The output is: $00009.0000000005
Enter dollars: 5
Enter cents: 3
$5.03
Enter dollars: 4
Enter cents: 2
$4.02
Enter dollars: 9
Enter cents: 2
$9.02
Enter dollars: 4
Enter cents: 9
$4.09
Enter dollars: 8
Enter cents: 7
$8.07
Enter dollars: 5
Enter cents: 9
$5.09
Enter dollars: 4
Enter cents: 8
$4.08
Enter dollars: 7
Enter cents: 9
$7.09
Enter dollars: 6
Enter cents: 1
$6.01
Enter dollars: 4
Enter cents: 8
$4.08
Want to see more full solutions like this?
Chapter 4 Solutions
Programming in C
Additional Engineering Textbook Solutions
Electric Circuits. (11th Edition)
Thinking Like an Engineer: An Active Learning Approach (4th Edition)
Java How to Program, Early Objects (11th Edition) (Deitel: How to Program)
Elementary Surveying: An Introduction To Geomatics (15th Edition)
INTERNATIONAL EDITION---Engineering Mechanics: Statics, 14th edition (SI unit)
Starting Out with Python (4th Edition)
- Ensure you answer the question asked at the end of the document. Do not just paste things without the GNS3 console outputsarrow_forward"Do not use AI tools. Solve the problem by hand on paper only and upload a photo of your handwritten solution."arrow_forward"Do not use AI tools. Solve the problem by hand on paper only and upload a photo of your handwritten solution."arrow_forward
- "Do not use AI tools. Solve the problem by hand on paper only and upload a photo of your handwritten solution."arrow_forward"Do not use AI tools. Solve the problem by hand on paper only and upload a photo of your handwritten solution."arrow_forwardSolve this "Do not use AI tools. Solve the problem by hand on paper only and upload a photo of your handwritten solution."arrow_forward
- "Do not use AI tools. Solve the problem by hand on paper only and upload a photo of your handwritten solution."arrow_forward"Do not use AI tools. Solve the problem by hand on paper only and upload a photo of your handwritten solution."arrow_forwardSpecifications: Part-1Part-1: DescriptionIn this part of the lab you will build a single operation ALU. This ALU will implement a bitwise left rotation. Forthis lab assignment you are not allowed to use Digital's Arithmetic components.IF YOU ARE FOUND USING THEM, YOU WILL RECEIVE A ZERO FOR LAB2!The ALU you will be implementing consists of two 4-bit inputs (named inA and inB) and one 4-bit output (named out). Your ALU must rotate the bits in inA by the amount given by inB (i.e. 0-15).Part-1: User InterfaceYou are provided an interface file lab2_part1.dig; start Part-1 from this file.NOTE: You are not permitted to edit the content inside the dotted lines rectangle. Part-1: ExampleIn the figure above, the input values that we have selected to test are inA = {inA_3, inA_2, inA_1, inA_0} = {0, 1, 0,0} and inB = {inB_3, inB_2, inB_1, inB_0} = {0, 0, 1, 0}. Therefore, we must rotate the bus 0100 bitwise left by00102, or 2 in base 10, to get {0, 0, 0, 1}. Please note that a rotation left is…arrow_forward
- Microsoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,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 Learning
- Programming with Microsoft Visual Basic 2017Computer ScienceISBN:9781337102124Author:Diane ZakPublisher:Cengage LearningEBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT




