1 #include<stdio.h>
2 int main()
3 {
4 int N,thousand,hundreds,tens,units ; //分别定义未知数N及其千、百、十、个位
5 for(N=1000;N<10000;N++) //因为N为一个四位数,所以循环为1000至10000
6 {
7 thousand = N/1000; //
8 hundreds = N/100%-thousand*10; //
9 tens = N/10%10; //
10 units = N%10; //分别取出千、百、十、分位数
11 if(N*9==units*1000+tens*100+hundreds*10+thousand) //判断所取出的千、百、十、分位数的组成是否满足N的9倍的逆序数,即个位变千位、十位变百位、百位变> 十位、千位变个位
12 {
13 printf("N = %d\n",N); //符合则打印
14 }
15 }
16 return 0;
17 }
【C语言基础练习】设N是一个四位数,它的9倍恰好是其反序数(例如:1234的反序数是4321),求N的值
最新推荐文章于 2024-02-13 11:15:43 发布