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

Stack using Linked List – Partial (University Exam Topic)

 #include <iostream> using namespace std; struct Node {     int data;     Node* next; }; class Stack {     Node* top; public:     Stac...