nyist 11 奇偶數分離

來源:互聯網
上載者:User

標籤:os   io   資料   for   時間   amp   ios   測試   

奇偶數分離
時間限制:3000 ms | 記憶體限制:65535 KB
難度:1
描述
有一個整型偶數n(2<= n <=10000),你要做的是:先把1到n中的所有奇數從小到大輸出,再把所有的偶數從小到大輸出。
輸入
第一行有一個整數i(2<=i<30)表示有 i 組測試資料;
每組有一個整型偶數n。
輸出
第一行輸出所有的奇數
第二行輸出所有的偶數

範例輸入
2
10
14範例輸出
1 3 5 7 9
2 4 6 8 10

1 3 5 7 9 11 13
2 4 6 8 10 12 14

 

#include<stdio.h>
int main()
{
int N;
scanf("%d",&N);
while(N--)

{
int n;
scanf("%d",&n);
for(int i=1;i<=n;i+=2)
printf("%d ",i);
puts("");

for(int i=2;i<=n;i+=2)
printf("%d ",i);
puts("");

}
}

 

 

 

 

#include<iostream>
using namespace std;
int main()
{
int N;
cin>>N;
while(N--)
{
int n,i,j;
cin>>n;

for (i=1;i<n;i+=2)
cout<<i<<" ";
cout<<endl;

for(j=2;j<=n;j+=2)
cout<<j<<" ";
cout<<endl;
}
return 0;
}

 

 

#include<stdio.h>
int main()
{

int n,m,i,j,k,t;
scanf("%d",&n); //表示有 n 組測試資料
{
for(i=0;i<n;i++)
{
scanf("%d",&m);
for(j=1;j<=m;j+=2)
{
printf("%d ",j); //第一行輸出所有的奇數

}
printf("\n");
for(j=1;j<=m;j+=1)
{
printf("%d ",j); // 第二行輸出所有的偶數

}
printf("\n\n");

}
}
return 0;

}

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.