#include<stdio.h>
#include<conio.h>
/* Function Declaration
int pal(int x); */
/*Declaring Second Function*/
int rev(int x);
int main()
{
int a, b, c;
clrscr();
printf("Enter The Number Which You Want To Check Is Palindrome Or Not\n");
scanf("%d", &a);
b = rev(a);
printf("%d", b);
if(b == a) {
printf("%d Is A Palindrome Number", a);
} else {
printf("%d Isn't A Plaindrome Number", a);
}
getch();
return(0);
}
int rev(int x)
{
int d = 0;
while(x) {
d = d * 10 + x % 10;
x = x / 10;
}
return(d);
}
我没有使用while(x)
陈述。我的意思是,我们通过while循环附加一些条件,即while(x!=0)
,那么独立while(x)
意味着什么。
while (x)
是相同的 while (x != 0)
对于整数数据类型,0为false
&其他均为true
。因此while (x)
将对while(true)
所有人进行评估x != 0
。
同样,您还会遇到类似while(!x)
或的表达式if(!x)
如果x
有值不为零,则x
是true
&!x
是false
。如果x
有值0
,则x
是false
&!x
是true
。
所以写作(!x)
和写作一样(x == 0)
您还将看到指针的类似用法。对于指针p
,(p)
与(p != NULL)
和(!p)
相同(p == NULL)
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句