ADDITIONAL EXERCISE TASKS IN THE FIELD: BRANCHING IN THE PROGRAM (SELECTIONS STATEMENTS)


This section provides examples of tasks in the field of branching in the program, with solutions. Try to solve the examples on your own, and use the solution to check or use if, after several attempts and a lot of effort, you still fail to solve the set task on your own.
The solution will be displayed by clicking on the button next to the set task.
The tasks are painted in different colors depending on the difficulty:
  • Green- easy tasks
  • Yellow - medium difficulty tasks
  • Red - harder tasks
Creating web applications -introduce. Frontend and background development. Read more on webpage
Creating web applications​Create a web application logo using the django framework by clicking on the image belowCreating django web application

Task 1: Free fall speed

The body falls freely from a height X to the ground. Determine whether this height must be greater than the entered initial height (H meters) for the body velocity to fall to be greater than vG (user input).

Input:
In one line of the standard input there are two real values ​​H and Vg (H≤3000, Vg≤300) which represent the initial height of the body in meters and the limit speed in m / s.

Output
Calculated fall speed as well as speed limit.

Example 1
Input
10 12
Output
"Height does not have to be more than 10 m for the body to reach a speed of 12 m / s"

Example2
Input
50 78
Output
"The height must be greater than 250 m for the body to reach a speed of 78 m / s"
Ramovi za slike-zadatak See what Simulation of free fall looks like on Projectile Motion

Task 2-High jump:

The third competitor won with a jump from the entered results that the competitor 1st and 3rd achieved in the high jump in the third jump.
If other results are known:
competitor 1: 5.87m, 5.94m, x
competitor 2: 5.89m, 5.84m, 5.75m;
competitor 3: 5.6m, 5.87, y;
determine the order of the competitors after this jump.

Input
Real numbers x and y, in the interval from (0 - 7)

Output
One real number, rounded to two decimal places, which represents the best result with the message that the competitor won.

Example
Input
5.45
5.76

Output
The first competitor won with a jump of 5.94
Grupa radnika-zadatak Image by Peggy und Marco Lachmann-Anke from Pixabay

Task 3-Correctness of square data


Enter the pages of squares a, b, c and determine whether the entered data is correct (page lengths must be positive numbers). If so, calculate the area and volume.

Input
Enter the real numbers a, b, c in the three lines of the standard input

Output
Two real numbers representing the area and volume of a square or
message that the data is incorrect

Example 1
Input
2
4
7

Output
P=100cm2
V=56cm3

Example 2
Input
12
-4
7
Output The data is incorrect
Kretanje tela - zadatak Image by Pete Linforth from Pixabay

Task 4-Enrollment at the faculty:

Entered points for 4 candidates for enrollment at the technical faculty. Create a program that determines whether candidates who want to enroll in a technical faculty meet the requirements for enrollment (Enrolled all who have a number of points above average).

Input
4 real numbers (0-100) should be entered in the first four lines.

Output
Show in 4 lines the answer for each candidate:
"Eligible", or
"Not eligible"

Example
Input
65 45 88 75
Output
"Not eligible"
"Not eligible"
"Meets the requirements"
"Meets the requirements"
Enrollment at the facultyImage by OpenClipart-Vectors from Pixabay

Task 5-Determining the number of days by months:


Determine the number of days for each month of the year. Predict the case and that the year is a leap year

Input
Two integers are entered from the standard input:
M (0≤a≤12) - ordinal number of the month in the year
G (0-2050) -current year

Output
Write one integer on the standard output - the number of days in that month

Example 1
Input
3
2021
Output
31
Example 2
Input
2
2020
Output
29
Determining the number of days by months Image by OpenClipart-Vectors from Pixabay

Task 6-Tax:

Write a program that calculates the amount of gross salary tax. If the gross salary is higher than 1000 euros, the tax is 20%, otherwise the tax is 15%. Gross salary is entered:
a) In EUR-lighter variant
b) In RSD - heavier variant, if the value of 1EUR: 117RSD

Input:
In one line of standard input, one real number from the interval [1..100000] is entered, which represents the gross salary

Output:
The value of the salary in euros is written on the standard output, as well as the tax (real number rounded to two decimal places).

Example 1 (For b variant, ie for entry in dinars)
Input
59900


Output
511.97 // salary in euros
76.79 // RSD


Operacije po modulu - zadatak

Task 7-Minimum of three integers:

Write a program that determines the minimum value of the three entered values ​​of the read temperature.
Input
From the standard input, three real numbers are entered, each in a separate row, which represent the values ​​of the three read temperatures (-50.50) during the day.

Output
Print the value of the minimum temperature rounded to 2 decimal places on the standard output

Example
Input
12.34
5.64
7.45

Output
5.64


Rastojanje tačaka - zadatak Image by Gerd Altmann from Pixabay

Task 8-Making color-RGB value:

​It is known that each shade of color can be obtained by mixing 3 components of red, green and blue. The components are represented by 3 integers whose values ​​are (0-255). This is the RGB value. Create a program that, for the loaded values ​​of R, G and B, determines which color shade predominates.

Input
Three integers are entered from the standard input, each in a separate line, representing R, G, B values ​​between 0 - 255.

Output
Print the name of the dominant color on the standard output

Example
Input
50
130
170

Output
"Blue"

9. Car race

The three cars start from the starting position at moments T1 <T2 <T3 and move at constant speeds V1, V2, V3. Print the start numbers of the cars that are in the leading position at time T> T3. It is possible that more than one will be in the leading position.

Input
Three real numbers that represent the delay time of the first, second and third cars in the first line.
In the second line, load 4 real numbers in a row that represent the speeds of 1,2 and 3 cars and at the end the race time in seconds until the moment when the intersection is made and it is determined which car or cars are in the leading position.

Output
A text that describes which car is in the leading position

Example
​

Input
1 2 3
23 23.6 22.8 60

Output
"The second car is in the lead"
Picture

10. Code of Characters

(It is known that characters (letters, numbers, special characters) are represented by associated integers. (Can be seen in the tables of ASCII codes.) From the table it can be seen that the codes of uppercase letters are 65-90, while the codes of lowercase letters are 97-122.So, the lowercase letter a has the code, for example 97, while the uppercase letter A has the code 65.
Create a program that determines for the general random value of the code of a character (1-150):
a) is not a letter, therefore, is it some other sign, such as e.g. digit or special character
b) If it is a letter, print it in uppercase or lowercase
Display both code and character generated on the outputNote: For generic random values, use the rand () function from the stdlib.h file. (Instead, you can allow the user to enter the number himself)Entrance
Randomly generated (or entered) integer 1-150
Exit
Some of the following messages:
  1.  "Not a letter but another character: 64 @"
  2.  "Capital letter 75 K"
  3.  "Lowercase letter 101 e"
  4.  "None of the above"

Example

Input
74

Output
"Capital letter 74 K"
TABLE OF ASCII CODESPicture

11. Man do not be angry

Create a program that simulates rolling dice using the rand () function from the stdlib.h file
Pera plays "Man, don't get angry" and he has the opportunity to finish the round by entering his pawn in the house. He rolls the dice and needs to get either 2 or 4 to enter the house. If he gets 1 he will cross into the field right next to his house.
The program should simulate rolling the dice, setting a random value of 1-6 using the rand function, and then print one of the following messages:
"She's in the cottage"
"It's close to the house"
"He didn't move"
Picture Image by GooKingSword from Pixabay