#include<iostream>//同构数#include<cmath>#include<iomanip>
using namespace std;
bool fun(int);intmain(){for(int i =1; i <20000; i ++)if(fun(i))
cout <<setw(8)<< left << i <<setw(16)<< left << i*i << endl;return0;}
bool fun(int num){int square = num*num;int i =1;int n = num;while(n/=10)//统计num个数
i++;for(int j =0; j < i; j++){int a = num%10;int b = square%10;if(a!=b)return false;
num /=10;
square /=10;}return true;}
2. 递归求数组中最小值
#include<iostream>
using namespace std;
template<class T>intfind_Min(const T [],int);intmain(){int a[]={4,2,3,67,7,5,3,45,1,23,56,0};
cout <<find_Min(a,3);return0;}
template<class T>//先处理后递归,更易于理解intfind_Min(cosnt T a[],int len){staticint small = a[0];if(len ==0)return small;if(small > a[len -1]){
small = a[len -1];}
small =find_Min(a,len-1);//find_Min(a, len - 1);也行}
template<clasee T>//先处理后递归intrecursiveMinimum(const T array[],int low,int high ){staticint smallest = MAXRANGE;//静态变量;if( array[ low ]< smallest )
smallest = array[ low ];return low == high ? smallest :recursiveMinimum( array, low +1, high );//是返回还是递归。不等递归,相等返回。}
template<class T>//先递归,后处理,在返回intselectSmallIndex(const T str[],int n ){int small =0;//small作为返回值,可以不用静态变量if(n ==1)
small =0;else{
small =selectSmallIndex(str,n -1);if(str[small]> str[n -1])
small = n -1;}return small;}