#include <stdio.h>
#include <stdlib.h>
#define SIZE 10
int main (int argc, char *argv[])
{
int a[5],b[5],c[10];
int i;
for (i=0; i<5; i++) {
a[i]=arc4random()%(1000-1+1)+1;
b[i]=arc4random()%(1000-1+1)+1;
printf("a[%d]=%d b[%d]=%d\n",i,a[i],i,b[i]);
}
for (i=0; i<5-1; i++)
{
for (int j=0; j<5-i-1; j++)
{
if (a[j]>a[j+1])
{
int temp=0;
temp=a[j+1];
a[j+1]=a[j];
a[j]=temp ;
}
}
}
for (i=0; i<5; i++) {
printf("a数组的升序排列为a[%d]=%d\n",i,a[i]);
}
for (i=0; i<5-1; i++)
{
for (int j=0; j<5-i-1; j++)
{
if (b[j]>b[j+1])
{
int temp=0;
temp=b[j+1];
b[j+1]=b[j];
b[j]=temp ;
}
}
}
for (i=0; i<5; i++) {
printf("b数组的升序排列为b[%d]=%d\n",i,b[i]);
}
for (i=0; i<5; i++) {
c[i]=a[i];
printf("c[%d]=%d\n",i,a[i]);
}
for (i=0; i<5; i++) {
c[5+i]=b[i];
printf("c[%d]=%d\n",5+i,b[i]);
}
for (i=0; i<10-1; i++)
{
for (int j=0; j<10-i-1; j++)
{
if (c[j]>c[j+1])
{
int temp=0;
temp=c[j+1];
c[j+1]=c[j];
c[j]=temp ;
}
}
}
for (i=0; i<10; i++) {
printf("c数组的升序排列为c[%d]=%d\n",i,c[i]);
}
return 0;
}
|
|