2 - Conditional and Iteration Statements
2 - Conditional and Iteration Statements
1. Write a program that asks for an integer and tells whether it is prime or not.
2. Write a program that reads the 3 coordinates of a vector in a three-dimensional space and
calculates the corresponding unit vector (vector with the same direction and length 1),
which is obtained dividing each coordinate of the original vector by its length. If the
entered vector is (0, 0, 0), the program will indicate that there is no unit vector.
4. Create a program that checks if a given date is correct. For this we will enter the day,
month and year.
5. Make a program to solve second degree equations. In order to do this, we will enter the
values of the coefficients a, b and c and then display the results.
7. Create a program that shows all odd numbers between 1 and 100.
8. Create a program that simulates 20 coin tosses. The results should be shown on the screen
in the form "heads" or "tails".
9. Create a program that displays on screen the first 15 terms of the Fibonacci series.
10. Write a program to obtain the Tarot number of a given date, checking first if the date is
correct. The Tarot number is obtained by adding all the digits so that they are reduced to a
single digit. We add the day, month and year first and then add each digit of the resulting
number.
11. Write a program that prints the sum of the multiples of 5 between two values a and b.
Negative values of a and b will not be allowed and it will be checked that a is less than b,
otherwise the values will be swapped.
Fundamentos de programación
12. Create a program that, based on a number of rows, draws a triangle as follows:
*
***
*****
*******
*********
13. Create a program that generates a random number between 0 and 100 and then gives 9
chances to guess that number, telling the user if he guesses correctly (by means of a
victory message) Otherwise, it will show a message indicating if the number entered is
higher or lower than the desired number. Before each new try, the screen will diaply how
many chances are left to guess the number. When the 9 chances are over, the number to
be guessed will be displayed on the screen together with a message saying the game is
over and the user has lost.
14. Write a program that displays an on-screen menu to implement a "mini-calculator". The
menu should let you choose addition, subtraction, multiplication, division or exit the
calculator. Once an operation is chosen the two operands will be requested and finally the
result will be displayed and the program will return to the main menu.