Question
Chapter 5 2. 3. What does the following statement print if i has the value 17? What does it print if i has the value-17?
Chapter 5 2.
3. What does the following statement print if i has the value 17? What does it print if i has the value-17?
printf("%d ", i >= 0 ? i : -i);
Write your answer here:
3.
4. The following if statement is unnecessarily complicated. Simplify it as much as possible. (Hint: The entire statement can be replaced by a single assignment.)
if (age >= 13)
if (age <= 19)
teenager = true,- else
teenager = false;
else if (age < 13)
teenager = false;
If so, what does it do when n is equal to 5?
Write your answer here:
4.
5. Are the following if statements equivalent? If not, why not?
(1)
if (score >= 90)
printf("A");
else if (score >= 80)
printf("B");
else if (score >= 70)
printf("C");
else if (score >= 60)
printf("D");
else
printf("F");
(2)
if (score < 60)
printf("F");
else if (score < 70)
printf ("D" );
else if (score < 80)
printf("C");
else if (score < 90)
printf("B");
else
printf("A");
Write your answer here:
5.
Programming Projects
5.2
1. Write a program that asks the user for a 24-hour time, then displays the time in 12-hour form:
Enter a 24-hour time: 21:11
Equivalent 12-hour time: 9:11 PM
Be careful not to display 12:00 as 0:00.
1. Write your program here:
#include
int main(){
return 0;
}
2. Heres a simplified version of the Beaufort scale, which is used to estimate wind force:
Speed (knots) | Description |
Less than 1 | Calm |
1~3 | Light air |
4~27 | Breeze |
28~47 | Gale |
48~63 | Storm |
Above 63 | Hurricane |
Write a program that asks the user to enter a wind speed (in knots), then displays the corresponding description.
2. Write your program here:
#include
int main(){
return 0;
}
3. Write a program that finds the largest and smallest of four integers entered by the user:
Enter four integers: 21 43 10 35
Largest: 43
Smallest: 10
Use as few if statements as possible. Hint: Four if statements are sufficient.
3. Write your program here:
#include
int main(){
return 0;
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started