Computer Science: A Structured Programming Approach Using C, Third Edition
3rd Edition
ISBN: 9780534491321
Author: Behrouz A. Forouzan, Richard F. Gilberg
Publisher: Course Technology, Inc.
expand_more
expand_more
format_list_bulleted
Concept explainers
Textbook Question
Chapter 5, Problem 10PS
Which of the following statements creates the "dangling else problem"?
a. a nested if statement without a false statement
b. a nested if statement without a true statement
c. a switch statement without a default
d. an if statement without a true or a false statement
e. any nested if statement
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
1. An if selection statement executes if and only if:
A. the Boolean condition evaluates to false.
B. the Boolean condition evaluates to true.
C. the Boolean condition is short-circuited.
D. none of the above.
Answer:
2.A compound statement is enclosed between:
A. [ ]
B. { }
C. ( )
D. < >
Answer:
4. The controlling expression for a switch statement includes all of the following types except:
A. char
B. int
C. byte
D. double
Answer:
Python Lab 5: if statements with else and elif
1. Write an if statement to
Ask the user to enter a number. Determine if the number is divisible by 5.
if (number % 5 == 0):
print (str(number) + ' is divisible by 5')
determine if a number is
divisible by 5.
2. Write an if/else statement.
An else statement can follow an if statement. The code in an else
statement is executed if the expression in the if statement is false.
if (number % 5 == 0):
print (str(number) +
' is divisible by 5')
else:
print (str(number) + ' is divisible by 5')
Notice that an else statement does not have a Boolean expression.
Write an additional iflelse statement to see if the number is divisible by 2.
Test your code with many different inputs.
3. Write an if/elif/else
The command elif can be used to make a series of if statements more
efficient. As soon as one of the expressions is true, the other ones are
skipped. elif is short for 'else if.
sequence.
Ask the user to enter a State/Province name, and print out the…
Can an else statement exit without an if statement preceeding it?
Chapter 5 Solutions
Computer Science: A Structured Programming Approach Using C, Third Edition
Ch. 5 - Prob. 1PSCh. 5 - The expression in a selection statement can have...Ch. 5 - Each labeled statement may identify one or more...Ch. 5 - The character classification functions are found...Ch. 5 - Prob. 5PSCh. 5 - The logical operator is true only when both...Ch. 5 - Prob. 7PSCh. 5 - Two-way selection is implemented with the ...Ch. 5 - Prob. 9PSCh. 5 - Which of the following statements creates the...
Ch. 5 - There are two different ways to implement a...Ch. 5 - Which of the following statements about switch...Ch. 5 - Which of the following statements about the...Ch. 5 - Prob. 14PSCh. 5 - Prob. 15PSCh. 5 - If x=0,y=5,z=5, what is the value of x, y, and z...Ch. 5 - If x=3,y=0,andz=4, what is the value of the...Ch. 5 - Simplify the following expressions by removing the...Ch. 5 - Prob. 19PSCh. 5 - If originally x=4,y=0,andz=2, what is the value of...Ch. 5 - If originally x=4,y=0,andz=2, what is the value of...Ch. 5 - If originally x=4,y=0,andz=2, what is the value of...Ch. 5 - If originally x=4,y=0,andz=2, what is the value of...Ch. 5 - If originally x=0,y=0,andz=1, what is the value of...Ch. 5 - If originally x=4,y=0,andz=2, what is the value of...Ch. 5 - If originally x=0,y=0,andz=1, what is the value of...Ch. 5 - If originally x=0,y=0,andz=1, what is the value of...Ch. 5 - If originally x=0,y=0,andz=1, what is the value of...Ch. 5 - If originally x=0,y=0,andz=1, what is the value of...Ch. 5 - If originally x=0,y=0,andz=1, what is the value of...Ch. 5 - If originally x=2,y=1,andz=1, what is the value of...Ch. 5 - If originally x=1,y=3,andz=0, what is the value of...Ch. 5 - Evaluate the value of the following expressions:...Ch. 5 - Evaluate the value of the following expressions:...Ch. 5 - Write an if statement that will assign the value 1...Ch. 5 - Prob. 36PSCh. 5 - Write the code to add 4 to an integer variable,...Ch. 5 - Prob. 38PSCh. 5 - Write the code to print either zero or not zero...Ch. 5 - If the variable divisor is not zero, divide the...Ch. 5 - Prob. 41PSCh. 5 - Rewrite the following code using one if statement:...Ch. 5 - Rewrite the following code fragment using one...Ch. 5 - Write a code fragment that tests the value of an...Ch. 5 - Prob. 45PSCh. 5 - Prob. 46PSCh. 5 - Write a function called smallest that, given three...Ch. 5 - Prob. 48PSCh. 5 - Write a function called month_of_year that, given...Ch. 5 - Write a function called parkingcharge that, given...Ch. 5 - Prob. 51PSCh. 5 - Complete the incremental implementation of Program...Ch. 5 - Write a program that determines a student's grade....Ch. 5 - Prob. 54PSCh. 5 - Given a point, a line from the point forms an...Ch. 5 - Prob. 56PSCh. 5 - Write a program that asks the user to enter the...Ch. 5 - Prob. 58PSCh. 5 - This program is a simple guessing game. The...Ch. 5 - Write a program that, given a person's birth date...Ch. 5 - Write a program that calculates the change due a...Ch. 5 - Write a menu-driven program that allows a user to...Ch. 5 - Write a program that tests a user-entered...Ch. 5 - Write a program to compute the real roots of a...
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- Given: If A AND B, then C. Given: The if-then statement's reverse is also correct. If A is True, B is True, what is C?  Forward and reverse / Forward and reverse  Not True or False  False  Truearrow_forwardGiven: If A AND B, then C. Given: The if-then statement's reverse is also correct. If A is True, B is True, what is C? A. Not True or False B. Forward and reverse/Forward and reverse C. False D. Truearrow_forward7. Which of the following statements is cocurrent statement ? A. continous assignment B. if-else statement C. begin-end block D. looping statementarrow_forward
- Write an if statement for the following : use if statement that sets the variable fees to 50 if the flag variable max is set totrue.arrow_forwardWrite an if statement for the following: use if/else statement that assigns 1 to x if y is equal to 100. Otherwise it should assign 0 to x.arrow_forwardOnly use If else statement.arrow_forward
- Given: If A AND B, then C. Given: The if-then statement's reverse isalso correct. If A is True, B is True, what is C?  Forward and reverse / Forward and reverse  False  Not True or False   True  i think a true but i dont want to guess what do you think?arrow_forwardGiven: If A AND B, then C. Given: The if-then statement's reverse isalso correct. If A is True, B is True, what is C?arrow_forwardRewrite the following if statements using the conditional operator:arrow_forward
- what is if statement ?arrow_forward1. What does if statement do. 2. What does for statement do. 3. Give the syntax for if statement, for statement, do while statement, while statement and switch statement. 4. What are the logical operators. 93 / ??arrow_forwardGiven: If A AND B, then C. Given: The if-then statement's reverse isalso correct. If A is True, B is True, what is C?  Forward and reverse / Forward and reverse  False  True  Not True or Falsearrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Control Structure in Data Structure - Data Structures - Computer Science Class 12; Author: Ekeeda;https://www.youtube.com/watch?v=9FTw2pXLhv4;License: Standard YouTube License, CC-BY