Count to N
Count to N. Given an integer N, write a program to print all the numbers from 1 to N, each on a new line. Test Input Output Test 1 5 1 2 3 4 5 Test 2 1 1 Test 3 10 1 2 3 4 5 6 7 8 9 10 Test 4 3 …
Python, Java
Count to N. Given an integer N, write a program to print all the numbers from 1 to N, each on a new line. Test Input Output Test 1 5 1 2 3 4 5 Test 2 1 1 Test 3 10 1 2 3 4 5 6 7 8 9 10 Test 4 3 …
White pawn move. A white chess pawn moves vertically upwards one square at a time. However, if the pawn is on row #2, it has the option to move either one or two squares upwards. Additionally, a white chess pawn can capture an opponent’s piece by moving diagonally upwards one square to the left or right. …
Sort three numbers. You are given three integers. Write a program that prints these integers in ascending order. Input Output 5 3 7 3 5 7 8 9 1 1 8 9 2 5 2 2 2 5
Vertices of rectangle. Given integer coordinates of three vertices of a rectangle whose sides are parallel to the coordinate axes, find the coordinates of the fourth vertex of the rectangle. In the first test the three given vertices are (1, 4), (1, 6), (7, 4). The fourth vertex is thus (7, 6). Input Correct answer …
Linear equation. Write a program that solves a linear equation ax = b in integers. Given two integers a and b (a may be zero), print a single integer root if it exists and print “no solution” or “many solutions” otherwise. Input Output 1 -2 -2 2 -1 no solution 5 15 3 -5 30 -6 -7 -7 1
Next day. Given the month (an integer from 1 to 12) and the day in it (an integer from 1 to 31) in the year 2017 (or in any other common year), print the month and the day of the next day to it. The first test corresponds to March 30 and March 31. The …
Days in month. Given a month – an integer from 1 (January) to 12 (December), print the number of days in it in the year 2017 (or any other non-leap year). Input Output 1 31 2 28 3 31 4 30 5 31
Leap year. Given the year number. You need to check if this year is a leap year. If it is, print LEAP, otherwise print COMMON. The rules in Gregorian calendar are as follows: a year is a leap year if its number is exactly divisible by 4 and is not exactly divisible by 100 a year is …
Chocolate bar. Chocolate bar has the form of a rectangle divided into n×m?×? portions. Chocolate bar can be split into two rectangular parts by breaking it along a selected straight line on its pattern. Determine whether it is possible to split it so that one of the parts will have exactly k squares. The program reads three …
Knight move. Chess knight moves like the letter L. It can move two cells horizontally and one cell vertically, or two cells vertically and one cells horizontally. Given two different cells of the chessboard, determine whether a knight can go from the first cell to the second in one move. The program receives the input …