At first, my program is as follows, has been the error, basically there is no logical error, compiled with C-free run-time sorting is useless, and later changed to be useful!
(i) the problematic procedure
#include <stdio.h>
#define LEN 10
void Sort (int arry[]);
int select_min (int arry[]);
int main ()
{
int a[10],num=0;
for (num=0;num<10;num++)/* Enter 10 digits */
{
scanf ("%d", &a[num]);
}
printf ("%d\n", sizeof (a)/sizeof (int));
printf ("%d\n", Select_min (a));
Sort (A,sizeof (a)/4);
for (num=0;num<10;num++)
{
printf ("%d", A[num]);
}
printf ("\ n");
return 0;
}
void Sort (int arry[])
{
int i=0,j=0,min=0;
int temp;
Arry_size=sizeof (Arry)/4;
For (i=j+1;sizeof (Arry)/4;i++)
For (j=0;j<sizeof (Arry)/4;j++)
{
Min=j;
For (i=j+1;i<sizeof (Arry)/4;i++)/* This for loop is to find the smallest value in each trip, and one less to lie down after finding it.
{
if (Arry[min]>arry[i])
min=i;/* Record Minimum */
}
if (min!=j)/* Put the first smallest in the front of the array */
{
Temp=arry[min];
ARRY[MIN]=ARRY[J];
Arry[j]=temp;
}
}
}
int select_min (int arry[])/* Find the smallest value in the array */
{
int m,min=0;
MIN=ARRY[0];
For (m=1;m<sizeof (Arry)/sizeof (int); m++)
{
if (Min>arry[m])
MIN=ARRY[M];
}
return MIN;
}
(b), the correct code after modification!
#include <stdio.h>
#define LEN 10
void Sort (int arry[],int);
int select_min (int arry[]);
int main ()
{
int a[10],num=0;
for (num=0;num<10;num++)/* Enter 10 digits */
{
scanf ("%d", &a[num]);
}
printf ("%d\n", sizeof (a)/sizeof (int));
printf ("%d\n", Select_min (a));
Sort (A,sizeof (a)/4);
for (num=0;num<10;num++)
{
printf ("%d", A[num]);
}
printf ("\ n");
return 0;
}
void Sort (int arry[],int arry_size)
{
int i=0,j=0,min=0;
int temp;
Arry_size=sizeof (Arry)/4;
For (i=j+1;sizeof (Arry)/4;i++)
for (j=0;j<arry_size;j++)
{
Min=j;
for (i=j+1;i<arry_size;i++)//This for loop is to find the smallest value in each trip, and one less to lie down after finding it.
{
if (Arry[min]>arry[i])
min=i;/* Record Minimum */
}
if (min!=j)/* Put the first smallest in the front of the array */
{
Temp=arry[min];
ARRY[MIN]=ARRY[J];
Arry[j]=temp;
}
}
}
int select_min (int arry[])/* Find the smallest value in the array */
{
int m,min=0;
MIN=ARRY[0];
For (m=1;m<sizeof (Arry)/sizeof (int); m++)
{
if (Min>arry[m])
MIN=ARRY[M];
}
return MIN;
}
Search
This article is from the "7378168" blog, please be sure to keep this source http://7388168.blog.51cto.com/7378168/1681200
A small program every day--choose a small problem when sorting!