eolymp
bolt
Try our new interface for solving problems
Məsələlər

Maraqlı ardıcıllıq

dərc olunub 22.02.23 18:27:59

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

dərc olunub 08.01.24 18:08:17

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<<" ";
    }
}

}

dərc olunub 08.01.24 19:23:10

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<<" ";
    }
}

}