Skip to content
Permalink
Fetching contributors…
Cannot retrieve contributors at this time
101 lines (97 sloc) 3.37 KB

Loops

  1. Write a program that prints all the numbers from 1 to N.
  • Write a program that prints all the numbers from 1 to N, that are not divisible by 3 and 7 at the same time.

  • Write a program that reads from the console a sequence of N integers and returns the minimal and maximal of them.

  • Write a program that calculates N!/K! for given N and K (1 < K < N).

  • Write a program that calculates *N!K! / (N-K)! for given N and K (1 < K < N).

  • Write a program that, for a given two integers N and X, calculates the sum S = 0!/X0 + 1!/X1 + 2!/X2 + ... + N!/XN

  • Write a program that reads a number N and calculates the sum of the first N members of the sequence of Fibonacci: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, ... Each member of the Fibonacci sequence (except the first two) is a sum of the previous two members.

  • Write a program that calculates the greatest common divisor (GCD) of given two numbers. Use the Euclidean algorithm (find it in Internet).

  • In the combinatorial mathematics, the Catalan numbers are calculated by the following formula:

    Screenshot

  • Write a program to calculate the Nth Catalan number by given N.

  • Write a program that prints all possible cards from a standard deck of 52 cards (without jokers). The cards should be printed with their English names. Use nested for loops and switch-case.

  • Write a program that reads from the console a positive integer N (N < 20) and outputs a matrix like the following:

N=3
1 2 3
2 3 4
3 4 5
N=4
1 2 3 4
2 3 4 5
3 4 5 6
4 5 6 7
* \*Write a program that calculates for given `N` how many trailing zeros are present at the end of the number N!. Examples: * N = 10 -> N! = 3628800 -> 2 * N = 25 -> N! = 15511210043330985984000000 -> 6
Does your program work for N = 50 000? Hint: The trailing zeros in N! are equal to the number of its prime divisors of value 5. Think why!
  • *Write a program that reads a positive integer N (N < 20) from console and outputs in the console the numbers 1 ... N2 numbers arranged as a spiral.
N=4
1 2 3 4
12 13 14 5
11 16 15 6
10 9 8 7
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.