Skip to content

Latest commit

 

History

History
35 lines (18 loc) · 3.85 KB

S03-EN-iterative-control-structures.md

File metadata and controls

35 lines (18 loc) · 3.85 KB

Iterative Control Structures

  1. E01-digit-sequence: Write an algorithm that reads a number N and calculates and prints the digits of N from left to right. Example: For the number "429356", the output should be '6'.

  2. E02-palindrome-check: Create an algorithm that determines if an N-digit number is a palindrome. Example: The number "87436863478" as well as the number "13655631".

  3. E03-pi-approximation: Write an algorithm using a loop to calculate the approximate value of π using the series: π = 4 − 4/3 + 4/5 − 4/7 + 4/9 . . . ± 4/n.

  4. E04-number-analysis: Given a sequence of numbers ending in zero, create an algorithm to calculate the percentage and sum of odd numbers, the percentage and sum of even numbers, the sum of all numbers, and how many numbers were entered. Example: If the numbers '12' '32' '85' '21' '19' '2' '17' '0' are entered, the output should be that the sum of all odd numbers is 46 and their percentage is 24.4681%, the sum of even numbers is 142 and their percentage is 75.5319%, the sum of all numbers is 188, and the total number of numbers entered was 7.

  5. E05-binary-to-decimal: Write an algorithm that takes as input a sequence of 0 and 1 numbers ending in −1 that represent a binary number and calculates the represented decimal number. Example: If the sequence is '1' '0' '0' '1' '0' '1' '-1', your algorithm should print 37.

  6. E06-fibonacci-sequence: Write an algorithm that takes as input a number N and prints the Fibonacci sequence up to N. The Fibonacci sequence starts with the numbers 0 and 1 and is calculated at each step by adding the last two numbers of the sequence. Example: The first numbers of the Fibonacci sequence are 0, 1, 1, 2, 3, 5, 8, 13, . . .

  7. E07-domino-values: Write an algorithm that prints the values of all domino tiles without repeating.

  8. E08-decimal-sequence: Write an algorithm that reads a sequence of digits between 0 and 9 ending in −1 that represent a decimal number and prints the decimal number. For example, if the input sequence is '5' '0' '3' '8' '-1', it should print "5038".

  9. E09-square-border: Write an algorithm that prints the border of a square with sides of size N. For example, if N = 5, the algorithm should print:

example

  1. E10-nested-squares: Write an algorithm that prints the borders of squares of odd size from N to 1 nested within each other. For example, if N = 7, it should print:

example

  1. E11-guessing-game: Write an algorithm that generates a random number between 1 and 100 and asks the user to guess the number. If the number is incorrect, the program should give the user a clue by telling them if the number is higher or lower than the secret number. The game should continue until the user guesses the number.

  2. E12-chessboard-rice: On a chessboard, one grain of rice is placed on the first square, double the grains on the second square, and so on until the 64th square. Design a program to present a list indicating the square number, the number of grains placed on that square, and the cumulative sum of grains up to that square.

  3. E13-prime-number: Develop a program that indicates whether a given positive integer is a prime number or not.

  4. E14-perfect-number: Design a program that indicates whether a given positive integer "M" is perfect or not. A number is perfect when the sum of all its divisors, except itself, equals the number. Example: 6 is exactly divided by 1, 2, and 3, which sum up to the original value: 6.

  5. E15-palindromic-prime: A positive integer is called a palindromic prime when it is prime and also remains prime when its digits are reversed. For example, 17, 31, 37, and 113 are palindromic primes because 71, 13, 73, and 311 are also primes. Design a program to indicate whether a given number N is a palindromic prime.