We define a sandwich number as a natural number with only two different digits and , forming a sequence . That is, the digit is the first and last digit of (it’s the bread), and the digit is repeated times in between the two digits (it’s the filling). For example, 121 is a sandwich number with , , and . And 4004 is a sandwich number with , and .
More examples of sandwich numbers: 7227, 41114, 966669, 10001, and
535.
Examples of numbers that are not sandwich numbers: 9,
12, 113311, 7878, 1234, 9991, 1000.
Implement a function is_sandwich that
receives a natural number and returns true if it is a
sandwich number and false otherwise.
The function header should be:
/**
* @pre n >= 0
* @post returns true if n is a sandwich number, false otherwise
*/
bool is_sandwich(int n);
You only need to submit the requested function; the main program will be ignored.
is_sandwich(0) -> false is_sandwich(11) -> false is_sandwich(454) -> true is_sandwich(123) -> false is_sandwich(5665) -> true is_sandwich(20001) -> false is_sandwich(344443) -> true