Check if palindrome

    0

    2

    Giovanny Gongora

    Codiga's C Recipes

    Check whether the number entered by the user is a palindrome or not. An integer is a palindrome if the reverse of that number is equal to the original number.

    #include <stdio.h>
    
    int ifPalindrome() {
      int n, reversed = 0, remainder, original;
      printf("Enter an integer: ");
      scanf("%d", &n);
      original = n;
      // reversed integer is stored in reversed variable
      while (n != 0) {
        remainder = n % 10;
        reversed = reversed * 10 + remainder;
        n /= 10;
      }
      // palindrome if orignal and reversed are equal
      if (original == reversed)
        printf("%d is a palindrome.", original);
      else
        printf("%d is not a palindrome.", original);
      return 0;
    }
    
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Playground
    • Snippets
    • Cookbooks
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.