Copy Code code as follows:
/*
Name: Use while to determine if the number entered is a palindrome
Copyright:by. Don't know the Internet
Author:yangbin
DATE:2014 Year February 18 04:29:07
Description: Use while to determine whether the number of user input palindrome, is a palindrome number return yes! otherwise no!
*/
# include <stdio.h>
int main (void)
{
int m,val,sum = 0;
printf ("Please enter a palindrome number, if it is a palindrome number return yes, otherwise return no:");
scanf ("%d", &val);
m = val;
while (m)
{
sum = sum*10+m%10;
M/= 10;
}
if (sum = = val)
printf ("yes\n");
Else
printf ("no\n");
}
/*
----------------------
This code is written by C-free 5.0 and outputs debug results
-----Output-----
Please enter a palindrome number, if it is a palindrome number return Yes, otherwise return to no:1221
YES
------Summary------
When you can't write this code, see how others write, and then understand the meaning of the Code;
This code is primarily the calculation of a process for a while.
*/
Process analysis of a while statement
Suppose the user input number 121, judge whether Palindrome number, M non 0 is true, otherwise false, for true output Yes, false output no;
1--->sum = sum*10+m%10 (sum = 0*10+121%10)//sum=0+1,sum=1
M/= ten (M=M/10)//m=121/10,m=12
2--->sum = sum*10+m%10 (sum=1*10+12%10)//sum=10+2,sum=12
M/10 =10 (M=M/10)//m=12/10,m=1
3--->sum = sum*10+m%10 (sum=12*10+1%10)//sum=120+1,sum=121
M/10 =10 (M=M/10)//m=1/10,m=0
m = 0 is false, output no