Răspuns:
#include <iostream>
using namespace std;
int main()
{
int n,a[50000],b[50000],k=0,m=0;
cin>>n;
for(int i=1;i<=n;i++)
{
if(i%2==1)
a[k++]=i;// 1 3 5 7 9 ...
else
b[m++]=i;// 2 4 6 8 ...
}
if(n%2==1)
{
for(int i=0;i<k;i=i+2)
if(i!=k-1)
cout<<a[i]<<" "<<b[i]<<" ";
else
cout<<a[i]<<" "; // 9
cout<<endl;
for(int i=1;i<m;i=i+2)
cout<<a[i]<<" "<<b[i]<<" ";
}
else
{
for(int i=0;i<k;i++)
if(i%2==0)
cout<<a[i]<<" ";
else
cout<<b[i]<<" ";
cout<<endl;
for(int i=0;i<k;i++)
if(i%2==1)
cout<<a[i]<<" ";
else
cout<<b[i]<<" ";
}
}
Explicație: