Answer to Question #274636 in C++ for khan

Question #274636

Write a C program to input number from user and check number is palindrome or not using while loop. 


1
Expert's answer
2021-12-06T16:43:54-0500
#include <stdio.h>
int main() {
  int n, reversed = 0, foo, bar;
    printf("Input: ");
    scanf("%d", &n);
    bar = n;


    while (n != 0) {
        foo = n % 10;
        reversed = reversed * 10 + foo;
        n /= 10;
    }


    if (bar == reversed)
        printf("%d is a palindrome.", bar);
    else
        printf("%d is not a palindrome.", bar);


    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment