王道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");
}

posted @ 2022-04-05 18:32  zccccc!  阅读(176)  评论(0)    收藏  举报