#include <stdio.h>
#include <stdbool.h>
int main(){
int n,i;
printf("请输入数组的长度:");
scanf("%d",&n);
int arr[n];
printf("请输入%d个整数:",n);
for (i=0;i<n;i++) {
scanf("%d",&arr[i]);
}
bool isAscending = true; //升序
bool isDescending = true; //降序
for (i=1;i<n;i++){
if (arr[i]>arr[i-1]){
isDescending = false;
}
else if (arr[i]<arr[i-1]){
isAscending = false;
}
}
if (isAscending){
printf("数组是升序排序的");
}
else if (isDescending){
printf("数组是降序排序的");
} else {
printf("数组既不是升序也不是降序");
}
return 0;
}
判断整数是递减还是递增
最新推荐文章于 2024-11-14 21:21:03 发布