1.5 25: Find special natural numbers

Description
A decimal natural number, its hexadecimal and hexadecimal representations are both three digits, and the order of the three digits of the hexadecimal and hexadecimal numbers is opposite. Program to find this natural number, and output and display.

Enter
None.
Output
three lines: the
first line is the decimal representation of this natural number; the
second line is the hexadecimal representation
of this natural number ; the third line is the nine representation of this natural number.
Sample input
(none)
Sample output
(not provided)

#include <iostream>
using namespace std;
#define MIN 81    ///对应9进制里面最小的三位数:100,  
#define MAX 342   ///对应7进制里面最大的三位数:666 
int main()
{
    
    
	int i, temp7, temp9, a[3], b[3], ans=0, j, k;
	for(i=MIN; i<=MAX; i++)
	{
    
    
		temp7 = temp9 = i;
		j=0; k=0;
		while(temp7)
		{
    
    
			a[j++] = temp7%7;
			temp7 /= 7;
		}
		while(temp9)
		{
    
    
			b[k++] = temp9%9;
			temp9 /= 9;
		}
		if(a[0]==b[2] && a[1]==b[1] && a[2]==b[0])
		{
    
    
			ans = i;
			break;
		}
	}
	temp7 = a[0]+a[1]*10+a[2]*100;
	temp9 = b[0]+b[1]*10+b[2]*100;	
	cout<<ans<<endl;
	cout<<temp7<<endl;
	cout<<temp9<<endl;
	return 0;
}
}

Guess you like

Origin blog.csdn.net/yansuifeng1126/article/details/112364651