eolymp
bolt
Try our new interface for solving problems
Problems

Interesting sequence

published at 2/22/23, 6:27:59 pm

If n is an even number, first half of the sequence will be -> even numbers in descending order {n, n-2, n-4, ... , 2} then other half of the sequence will be odd numbers in ascending order {1, 3, 5, ... , n-1}

But if n is an odd number, alqorithm will be reversed

published at 1/8/24, 6:08:17 pm

include <bits/stdc++.h>

using namespace std; int main() {

int n, say = 0;
cin>>n;
if(n%2){
    for(int i = n; i >= 1; i -= 2){
        cout<<i<<" ";
    }
    for(int i = 2; i <= n; i += 2){
        cout<<i<<" ";
    }
}
else{
    for(int i = n; i >= 1; i -= 2){
        cout<<i<<" ";
    }
    for(int i = 1; i <= n; i += 2){
        cout<<i<<" ";
    }
}

}

published at 1/8/24, 7:23:10 pm

include <bits/stdc++.h>

using namespace std;

int main() {

int n;
cin>>n;
int a[n],b[n];
a[0] = 1;
if(n%2==0){
    for(int i = 0;i<(n/2);i++){
        cout<<n-2*i<<" ";
    }
    for(int j = 0;j<(n/2);j++){
        cout<<2*(j+1)-1<<" ";
    }
}
else{
    for(int j = 0;j<=(n/2);j++){
        cout<<n-2*j<<" ";
    }
    for(int i = 0;i<(n/2);i++){
        cout<<(i+1)*2<<" ";
    }
}

}