![Programming in C](https://www.bartleby.com/isbn_cover_images/9780321776419/9780321776419_largeCoverImage.gif)
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
{
}
![Check Mark](/static/check-mark.png)
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
Absolute Java (6th Edition)
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
Starting Out with Python (4th Edition)
Web Development and Design Foundations with HTML5 (8th Edition)
Starting Out With Visual Basic (7th Edition)
Starting Out with C++ from Control Structures to Objects (9th Edition)
- What is the output of the following code segment?inta=3,b=4;if(ab)Write(Y);WriteLine(Z); Y Z YZ nothingarrow_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_forwardplease help on this python code. Fill in the #lines and what is asking. Write a new code please.arrow_forward
- do it fastarrow_forwardA particular talent competition has 5 judges, each of whom awards a score between 0 and 10 to each performer. Fractional scores, such as 8.3, are allowed. A performer’s final score is determined by dropping the highest and lowest score received, then averaging the 3 remaining scores. Write a program that uses these rules to calculate and display a contestant’s score. It should include the following functions: • void getJudgeData() should ask the user for a judge’s score, store it in a reference parameter variable, and validate it. This function should be called by main once for each of the 5 judges. • double calcScore() should calculate and return the average of the 3 scores that remain after dropping the highest and lowest scores the performer received. This function should be called just once by main and should be passed the 5 scores.Two additional functions, described below, should be called by calcScore, which uses the returned information to determine which of the scores to drop.•…arrow_forwarduse only up to input, if, elif, else functions - basic pythonarrow_forward
- Hi All, Need help with this homework question. All coding is in Python. 1.) Rectangle Area The area of a rectangle is calculated according to the following formula: Area= Width * Length Design a function that accepts a rectangle's width and length as arguments and returns the rectangle's area. Use the function in a program that prompts the user to enter the rectangle's width and length, and then displays the rectangle's area. All coding is done in Python.arrow_forwardThe following function has errors. Locate as many errors as you can. void area(int length = 30, int width) { return length * width; }arrow_forwardLanguage: Python Write a function named factorial(x) that computes the factorial of a number. Include a docstring. Make sure you throw an error (such as ValueError) if x is negative or not an integer. You must implement this yourself (you can't use math.factorial). You can use the following procedure for the factorial: Set the result to 1 Loop over the values 1 to x, multiplying the result each time Return the result Here (as in later problems), I'll put ... where you should write code. Fill in the following: -> # write a function that calculates the factorial of an integer def factorial(x):... # !Check for input is integer or not, must be integer # print something that says integer or not # do calculations and return final result (several lines) result = 1 # use for-loop to calculate the factorial given x and return result ... # your input (you may use input command to ask user input) x = 10 factorial(x)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 LearningMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,
![Text book image](https://www.bartleby.com/isbn_cover_images/9781133187844/9781133187844_smallCoverImage.gif)
![Text book image](https://www.bartleby.com/isbn_cover_images/9781337102087/9781337102087_smallCoverImage.gif)
![Text book image](https://www.bartleby.com/isbn_cover_images/9781337102100/9781337102100_smallCoverImage.gif)