SubhanXd
Centipat
- Katılım
- 5 Kasım 2022
- Mesajlar
- 186
- Çözümler
- 1
Selamlar. Yapmam gereken :
"Given a sequence of integers, check if it is in ascending order, descending order, or neither. An ascending sequence is a sequence in which each element is greater than to the previous element. A descending sequence is a sequence in which each element is less than to the previous element. If none of these conditions are met, the sequence is neither ascending nor descending."
Yazdığım kod :
"Given a sequence of integers, check if it is in ascending order, descending order, or neither. An ascending sequence is a sequence in which each element is greater than to the previous element. A descending sequence is a sequence in which each element is less than to the previous element. If none of these conditions are met, the sequence is neither ascending nor descending."
Yazdığım kod :
Kod:
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
int size;
cin >>size ;
int array [size] ;
for (int f = 0 ; f < size ; ++f) {
cin >> array[f] ;
}
bool Ascending = false;
for (int f = 1 ; f <size ; ++f) {
if (array[f] > array[f-1]) {
Ascending = true ;
}
}
bool Descending = false ;
for (int f =1 ; f <= size- 1 ; ++f) {
if (array[f] < array [f+1]) {
Descending = true ;
}
}
if (Ascending && Descending == false ) {
cout << "Ascending" << endl ;
}
else if (Descending && Ascending == false) {
cout << "Descending" << endl ;
}
else {
cout << "Neither" << endl ;
}
}