我有以下来源,当我执行它时,值的符号会发生变化。我无法找出我哪里出错了。任何建议都有帮助
代码
#include <stdio.h>
#include <stdlib.h>
int arrsort(int *arr, int size);
int display(int *arr, int size);
int main()
{
int s_o_1=0, s_o_2=0;
int i; //index for arrays
int a[s_o_1],b[s_o_2];
printf("enter the size of the first array\n");
scanf("%d",&s_o_1);
printf("Enter the values of the first array\n");
for (i=0;i<s_o_1;i++)
{
scanf("%d",&a[i]);
}
printf("enter the size of the second array\n");
scanf("%d",&s_o_2);
printf("Enter the values of the second array\n");
for (i=0;i<s_o_2;i++)
{
scanf("%d",&b[i]);
}
//sort the first array
arrsort(a,s_o_1);
printf("The sorted first array is\n");
display(a,s_o_1);
//sort the second array
arrsort(b,s_o_2);
printf("The sorted second array is\n");
display(b,s_o_2);
}
int arrsort(int *arr, int size)
{
int temp; //for holding the temp value
int i; //for indexing
int j;
for(j=0;j<size;j++)
{
for(i=0;i<size;i++)
{
if(arr[i]>arr[i+1])
{
temp=arr[i];
arr[i]=arr[i+1];
arr[i+1]=temp;
}
}
}
}
int display(int *arr, int size)
{
int i; //array index
for (i=0;i<size;i++)
{
printf("%d\t",i);
}
printf("\n");
for (i=0;i<size;i++)
{
printf("%d\t",arr[i]);
}
printf("\n");
}
输出
enter the size of the first array
5
Enter the values of the first array
1 5 -10 -15 3
enter the size of the second array
5
Enter the values of the second array
-3 -5 15 9 10
The sorted first array is
0 1 2 3 4
-15 -10 3 5 10
The sorted second array is
0 1 2 3 4
-15 -10 -5 -3 9