Rupeek | Online Assessment | Pairs with given sum with constraints
Anonymous User
702

Write a program to find pairs of positive integers (A, B) whose sum is equal to the input number
N (N < 10 power 6).
The conditions to be satisfied by A & B are:
● A has at least two digits and starts with a non-zero digit
● B always has one digit less than A
● B can start with 0
● B is obtained from A by leaving out one digit.
The output should also indicate the number of such pairs. For example, if we input 1002 to the
program, the output should be as follows:
4 pairs found:
906 + 96 = 1002
911 + 91 = 1002
951 + 51 = 1002
1001 + 001 = 1002

2
1002
11
Line 1: Number of test cases
Line 2 Onwards: The Number itself
Print the output in the following format.

TEST #1
4 pairs found
906 + 96 = 1002
911 + 91 = 1002
951 + 51 = 1002
TEST #2
1 pair found
10 + 1 = 11

Comments (1)