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
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)
- Which, if any, of the following C statements contain variables whose values are replaced?a) scanf( "%d%d%d%d%d", &b, &c, &d, &e, &f );b) p = i + j + k + 7;c) printf( "Values are replaced" );d) printf( "a = 5" );arrow_forwardWhat is the output of the following code segment?inta=3,b=4;if(ab)Write(Y);WriteLine(Z); Y Z YZ nothingarrow_forwardAssume that you have a variable declared as intvar1=3;. Which of the following would display X 3X? WriteLine(X{0}X,var1); WriteLIne(X{0,2}X,var1); WriteLine(X2,0X,var1); WriteLine(X{0}{2},var1);arrow_forward
- Which of the following expressions is equivalent to the following code segment?if(gh)if(gk) Write(Brown); if(ghgk)Write(Brown); if(ghk)Write(Brown); if(ghgk)Write(Brown); two of thesearrow_forwardIf you run the following program, in which order the statements of this program will be executed? Your answer should be a sequence of comma separated line numbers without any extra spaces, e.g., 1,2,3,4,5,6,7,8 etc.arrow_forward12. Find the value of variable z after the execution of the statements given below. int z = 4; z = z<<4:arrow_forward
- Develop a program that will accept three integers from the user and displays the smallest and largest of the numbers each in a separate line. Don’t use max and min functions. It's Only An Exercise Not examarrow_forwardWhat is the output of the following statements? b. cout << "y != z - 9: " << (y != z - 9) << endl;c. cout<<"x-y==z+10:"<<(x-y==z+10)<<endl;d. cout << "!(z < w): " << !(z < w) << endl;arrow_forwardwhat is the output of the following code segment? int x = 350; int y = 0; do { y +=x 0; X = x/10; } while (x!=0); cout<arrow_forward
- I need help writing a Boolean expression that is true if and only if a student is a senior who is majoring in either Information Technology or Computer Science and has a GPA of at least 3.5 but not higher than 3.85. Assume that the student’s year in school is stored in the variable year, the student’s major is stored in the variable major, and the student's GPA is stored in the variable gpa. Use parentheses to indicate clearly the order in which the operations should be evaluated.arrow_forwardWhich statement is used to check for errors in your python code? A. if B. for C. try D. whilearrow_forwardIn a Python program, how do you convert data entered at the keyboard into a whole number? a. Just enter numbers on the keyboard. b. Use the int() function. c. Divide by 10. d. Use the find_number() function. Which of the following is NOT a conditional operator? a. = b. > c. < d. ==arrow_forward
- Microsoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning