帮忙解决一条c++题目

来源:百度知道 编辑:UC知道 时间:2024/05/22 17:58:23
函数find用来判断数组a中的数据是升序、降序还是无序。若为升序返回1,若为降序返回2,无序返回3。行参n为数组a中有效整数的个数,数组a从a[1]-a[n]中包含待判定的元素个数。请将程序补充完整。
int find(int a[],int n)
{int s,i;
if(a[1]<a[2]_____;
else s=2;
if(s==1)
{i=2;
while(1<n)
{if (_______________)
{s=3;
break;
}
return s;}

1.s=1

2.a[i++]>=a[i+1]

题目有个地方应该是while(i<n)吧

#include <iostream>

using namespace std;

int find(int a[],int n)
{
if(n<2)
{
cout<<"the number is small"<<endl;
return 0;
}
int s,i;

if(a[1]<a[2])s=1;
else s=2;

if(s==1)
{
i=2;
while(i<n)
{
if(a[i-1]>a[i++])
{
s=3;
break;
}
}
return s;
}
else if(s==2)
{
i=2;
while(i<n)
{
if(a[i-1]<a[i++])