A small program every day--choose a small problem when sorting!

Source: Internet
Author: User

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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.