王道oj/problem7(判断数字是否为对称数)
网址:http://oj.lgwenda.com/problem/7
思路:用temp保存原数;
不断对原数进行/10及取余运算,并加到num2中;
最后判断num2是否与temp相等。
代码:
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
//判断整型数是否为对称数
int main()
{
int num1,num2=0;
scanf("%d", &num1);
int temp = num1;
while (num1)
{
num2 *= 10;
num2 += num1 % 10;
num1 /= 10;
}
if (num2 == temp)
{
printf("yes");
}
else printf("no");
}
浙公网安备 33010602011771号