0% found this document useful (0 votes)
40 views2 pages

2 - Conditional and Iteration Statements

This document contains 14 programming exercises involving conditional and iteration statements. The exercises cover topics like checking if a number is prime, calculating a unit vector, checking for leap years, validating dates, solving quadratic equations, determining NIF letters, printing odd numbers, simulating coin tosses, calculating the Fibonacci series, determining Tarot numbers from dates, summing multiples between values, drawing triangles based on row count, guessing random numbers with chances, and implementing a mini-calculator menu.

Uploaded by

Aida
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views2 pages

2 - Conditional and Iteration Statements

This document contains 14 programming exercises involving conditional and iteration statements. The exercises cover topics like checking if a number is prime, calculating a unit vector, checking for leap years, validating dates, solving quadratic equations, determining NIF letters, printing odd numbers, simulating coin tosses, calculating the Fibonacci series, determining Tarot numbers from dates, summing multiples between values, drawing triangles based on row count, guessing random numbers with chances, and implementing a mini-calculator menu.

Uploaded by

Aida
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Fundamentos de programación

Worksheet – 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.

3. Make a program that checks if a year is a leap year.


• If divisible by 4, it is a leap year.
• If divisible by 100, it is not a leap year.
• If divisible by 400, it is a leap year.

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.

6. Write a program to determine the letter of a NIF.

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.

You might also like