思路:
1.首先将100个整数随机值存在a数组中
2.用for循环和rand函数从100个整数中选出10个序号,将a数组对应的序号的值赋给从零到10赋给b数组
3.用if语句判断奇偶性,用不同的指针存放奇数和偶数
4.用冒泡排序算法将两个指针对应的数组进行降序排序
5.输出两个指针对应数组的值
#include <iostream>
#include <cstdlib>
#include <ctime>
#define N 100
using namespace std;
int main()
{
int j,a[N], b[N],e[N],f[N], *c, *d,t1=0,t2=0;
srand((int)time(0)); // 产生随机种子 把0换成NULL也行
c = e;
d = f;
for (int i = 0; i < N; i++)
{
a[i] = rand()%100;
}
for (int i = 0; i < 10; i++)
{
j = rand() % 100;
b[i] = a[j];
if (b[i] % 2 == 0)
{
*c = b[i];
t1++;
//cout << *c;
c++;
//cout << "ou"<<t1;
}
if(b[i]%2!=0)
{
*d = b[i];
t2++;
//cout << *d;
//cout << "ji" << t2;
d++;
}
//cout << endl;
}
for (int i = 0; i < t1 - 1; i++)
{
for (int j = 0; j < t1 - i - 1; j++)
{
int t = 0;
if (e[j] < e[j+1])
{
t = e[j];
e[j] = e[j + 1];
e[j + 1] = t;
}
}
}
for (int i = 0; i < t2 - 1; i++)
{
for (int j = 0; j < t2 - i - 1; j++)
{
int t = 0;
if (f[j ] < f[j + 1])
{
t = f[j];
f[j] = f[j + 1];
f[j + 1] = t;
}
}
}
for (int i = 0; i < t1; i++)
{
cout << "oushu" << endl;
cout <<e[i] << endl;
}
for (int i = 0;i <t2; i++)
{
cout << "jishu" << endl;
cout << f[i]<< endl;
}
return 0;
}