Menu
Coddy logo textTech

Introduction

Lesson 19 of 20 in Coddy's Mathematical Riddles course.

A palindrome is a word, number, phrase, or other sequence of characters which reads the same backward as forward, such as 5, 11, 33 or 717.

Naturally, some of the numbers are palindrome in base-2 numeral system:

510 = 1012, 2710 = 110112, 3310 = 1000012, 71710 = 10110011012

challenge icon

Challenge

Easy

Write a function isBase2Palindrome that receives a number and return True if the number is a palindrome in base-2, and False otherwise.

Try it yourself

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include "solution.h"

int main() {
    int n;
    if (scanf("%d", &n) != 1) n = 0;
    bool r = isBase2Palindrome(n);
    printf("%s\n", r ? "true" : "false");
    return 0;
}

All lessons in Mathematical Riddles

7Least common multiple

IntroductionA problem

10Palindromes

Introduction196-algorithm