C language exercises have 10 integers stored in a one-dimensional array. Find the smallest number among these numbers and its subscript, and then exchange it with the front element of the array.

There are 10 integers stored in a one-dimensional array. Find the smallest number among these numbers and its subscript, and then exchange it with the front element of the array . a[10]={87,78,69,79,98,86,91,75,71,95}.

#include <stdio.h>
int main()
{
    
    
	int a[10]={
    
    87,78,69,79,98,86,91,75,71,95};
	int i,min=a[0],row,t;
	for(i=0;i<10;i++)
	{
    
    
	 	if(a[i]<min)
		{
    
    
			min=a[i];
			row=i;
		}
	 }
	 t=a[row];
	 a[row]=a[0];
	 a[0]=t;
	 printf("Min=a[%d]=%d\n",row,min);
	 for(i=0;i<10;i++)
	 {
    
    
	 	printf("%d ",a[i]);
	 }
	return 0;
}

Guess you like

Origin blog.csdn.net/usunshineboy/article/details/117304303