Control structures are programming constructs that allow developers to control the flow of execution in a program.
- If/else statements are used to execute certain code blocks based on a particular condition.
- Here, the condition is a Boolean expression that evaluates to either true or false. If the condition is true, the code inside the first block is executed, and if the condition is false, the code inside the second block is executed.
Loops are used to execute a block of code repeatedly until a certain condition is met. There are three types of loops in most programming languages: for, while, and do-while loops.
- In a for loop, the loop variable is initialized, a condition is specified, and an increment or decrement is performed after each iteration of the loop.?
- In a while loop, the condition is tested at the beginning of each iteration of the loop.?
- In a do-while loop, the condition is tested at the end of each iteration of the loop, so the loop is guaranteed to execute at least once.
- Write a program that prints the numbers from 1 to 100. For multiples of three, print "Fizz" instead of the number, and for multiples of five, print "Buzz". For numbers that are multiples of both three and five, print "FizzBuzz".?
- Write a program that prompts the user to enter a positive integer and then prints all the factors of that integer.?
- Write a program that takes two integers as input and then finds the greatest common divisor of the two integers using the Euclidean algorithm.?
- Write a program that prompts the user to enter a sequence of numbers terminated by -1 and then calculates the sum and average of the sequence.?
- Write a program that generates a random integer between 1 and 100 and asks the user to guess the number. The program should keep prompting the user to guess until they correctly guess the number.?
- Write a program that reads in a list of integers and then prints out the largest and smallest integers in the list.?
- Write a program that prompts the user to enter a sequence of numbers and then sorts the numbers in ascending order.?
- Write a program that prompts the user to enter a sequence of strings and then sorts the strings in alphabetical order.?
- Write a program that reads in a list of numbers and then removes any duplicates from the list.?
- Write a program that prompts the user to enter a sentence and then prints out the number of vowels in the sentence.