Menu
Coddy logo textTech

Introduction

Lektion 19 von 20 im Kurs Mathematische Rätsel von Coddy.

Ein Palindrom ist ein Wort, eine Zahl, eine Phrase oder eine andere Folge von Zeichen, die vorwärts wie rückwärts gleich gelesen wird, wie zum Beispiel 5, 11, 33 oder 717.

Natürlich sind einige der Zahlen Palindrome im Zweiersystem:

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

challenge icon

Aufgabe

Einfach

Schreiben Sie eine Funktion isBase2Palindrome, die eine Zahl erhält und True zurückgibt, wenn die Zahl in Basis-2 ein Palindrom ist, andernfalls False.

Probier es selbst

#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;
}

Alle Lektionen in Mathematische Rätsel

7Least common multiple

IntroductionA problem

10Palindromes

Introduction196-algorithm