Exercises
Write a program, that
input and output
- reads a number from input and prints it
- reads two numbers and prints their sum
elementary computations
- reads an angle (in radians) and prints the same angle in degrees (then the same in opposite direction)
- reads coordinates of two points and prints their distance
- reads a height of a tower (in meters) and prints the time, how long a piece of stone will fall down from the top of the tower
- reads a time given in seconds, converts it to hours, minutes and seconds and prints it
branching
- reads two numbers and prints the larger of them
- reads three numbers and prints the largest of them
- reads three numbers and decides if they are ordered from the smallest to the largest
- reads lengths of three sides of a triangle, then decides, if such triangle can be constructed, and prints the result
- reads coefficients a, b, c of a quadratic equation and prints its roots, if they are real; otherwise prints information that there are no real roots
loops and sequences (can be solved without using arrays and Matlab functions)
- reads a sequence of nonzero integers terminated by zero (the zero is used just for terminating, it is not a part of the sequence) and prints its running sum
- reads a sequence of numbers until their sum exceeds 20 or their number exceeds 5
- prints first 20 numbers of the Fibonacci sequence (it starts with numbers 0 and 1, then every next number is a sum of the two numbers preceeding it)
- prints all numbers of the Fibonacci sequence less than 900
- reads nonnegative integer n and then n real numbers, prints their average
- reads nonnegative integers m, n and prints all multiples of 3 in the interval from m to n
- reads sequence of real numbers representing moves on an account (deposits and withdrawals), prints one of the following informations:
- maximal and minimal deposit
- average deposit and average withdrawal
- final amount on the account (assume zero amount in the beginning)
- was anytime an actual amount on the account negative?
- was any withdrawal larger than 100?
- reads a sequence of nonzero integers and prints one of the following informations:
- how many positive numbers are there in the sequence, how many negative numbers
- the largest and the smallest number in the sequence
- if the number 7 appears in the sequence at least 3-times
- if there is at least one negative number in the sequence
- 2 largest numbers
- if there is somewhere a jump (difference) between two subsequent numbers greater than 5
- if the sequence is the Fibonacci one (without the first zero, i.e. it starts by a pair of ones and every number is equal to a sum of two preceeding numbers)
- if the sequence is growing, decreasing, nongrowing, nondecreasing or nothing of this sort
arrays (one dimensional)
- reads nonnegative integer n and then n real numbers, prints
- these numbers in reverse order
- these numbers ordered from the smallest to the largest
- reads a sequence of nonzero integers terminated by zero (the zero is used just for terminating, it is not a part of the sequence) and prints
- the number which is closest to the average
- how many numbers are less than average
- reads a sequence of positive integers with values less than 100 terminated by zero (the zero is used just for terminating, it is not a part of the sequence) and prints the number(s) with the highest frequency in the sequence and the frequency