Pages

Thursday, December 19, 2024

C- Palindromic Number Checker

 #include<stdio.h>

int main() {


// Declare the variables for Palindromic Number

int num, originalNum, remainder, result = 0;



printf("Enter an integer: ");

scanf("%d", &num);


originalNum = num; // Store the original number


// Reverse the number

while (num != 0) {

    remainder = num % 10; // Get the reversed number

    result = result * 10 + remainder; // Build the reversed number

    num /= 10; // remove the last digit

}


// Check if the no. is Palindrome is not


if (originalNum == result)

    printf("%d is a Palindromic Number.\n", originalNum);

else

    printf("%d is not a Palindromic Number. \n", originalNum);


return 0;


}


No comments:

Post a Comment

remove duplicates from sorted array - two pointer approach (leetcode)

  class Solution {     public int removeDuplicates ( int [] nums ) {         // base case: return if array have no el.         if ( nums...