#include<iostream>
using namespace std;
{
if(n==0)
{
cout<<"数组中无数据!!";
exit(0);
}
else if(n==1)
return true;
else
{
return (Result(a,n-1)&&(a[n-1]>a[n-2]));
}
}
int main()
{
int a[]={1,3,5,7,9};
int b[]={8,6,4,2,0};
int length_a=sizeof(a)/sizeof(a[0]);
int length_b=sizeof(b)/sizeof(int);
if(Result(a,length_a))
cout<<"数组a[]是递增数组"<<endl;
else
cout<<"数组a[]不是递增数组"<<endl;
cout<<endl;
if(Result(b,length_b))
cout<<"数组b[]是递增数组"<<endl;
else
cout<<"数组b[]不是递增数组"<<endl;
cout<<endl;
system("pause");
return 0;
using namespace std;
//使用递归算法对数组进行判定的函数!!
bool Result(int a[],int n){
if(n==0)
{
cout<<"数组中无数据!!";
exit(0);
}
else if(n==1)
return true;
else
{
return (Result(a,n-1)&&(a[n-1]>a[n-2]));
}
}
int main()
{
int a[]={1,3,5,7,9};
int b[]={8,6,4,2,0};
int length_a=sizeof(a)/sizeof(a[0]);
int length_b=sizeof(b)/sizeof(int);
if(Result(a,length_a))
cout<<"数组a[]是递增数组"<<endl;
else
cout<<"数组a[]不是递增数组"<<endl;
cout<<endl;
if(Result(b,length_b))
cout<<"数组b[]是递增数组"<<endl;
else
cout<<"数组b[]不是递增数组"<<endl;
cout<<endl;
system("pause");
return 0;
}
结果见下图: