# Basically Im reversing number and checking if they match or not. Even though number matches I am not getting the output

#include <stdio.h>
#include <math.h>
int main()
{
int i,a,b,c=0,n=4;
scanf("%d",&i);
while(i>0)
{
a=i%10;
b=a*(pow(10,n));
c=c+b;
i=i/10;
n=n-1;
}
if(c==i)
{
printf("%d\n",c);
printf("Numbers are identical");
}
else
{
printf("%d\n",c);
printf("Numbers are not identical");
}
return 0;
}

answered Oct 18, 2021 by (77,930 points)
edited Oct 18, 2021 by Peter Minarik

You read the original number into the variable i, which you keep modifying later in the code until it actually reaches the value 0. So later on when you compare the i to c, you actually compare 0 to c and not the original input from the user.

Furthermore, your code only works for exactly 5 digit long non-negative integral numbers and 0.

Below is a solution for any int input:

```#include <stdio.h>

int main()
{
// Read a number from the user
int number;
scanf("%d", &number);

// Reverse the order of digits
int reversedNumber = 0;
for (int tmp = number; tmp > 0; tmp /= 10)
{
reversedNumber *= 10;
reversedNumber += tmp % 10;
}

// Print the result
if (number == reversedNumber)
printf("The number reads the same backward.\n");
else
printf("The number does not read the same backward.\n");

return 0;
}```