-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9a9ae1c
commit fe67374
Showing
1 changed file
with
34 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,36 @@ | ||
#include<stdio.h> | ||
#include<conio.h> | ||
void main() | ||
{ | ||
clrscr(); | ||
int a[20],i,j,size,temp,loc,min; | ||
printf("enter array size"); | ||
scanf("%d",&size); | ||
printf("enter array element"); | ||
for(i=0;i<size;i++) | ||
scanf("%d",&a[i]); | ||
//selection sorting | ||
for(i=0;i<(size-1);i++) | ||
{ | ||
min=a[i]; | ||
loc=i; | ||
|
||
for(j=i+1;j<size;j++) | ||
{ | ||
if(a[j]>min) | ||
{ | ||
min=a[j]; | ||
loc=j; | ||
} | ||
} | ||
temp=a[i]; | ||
a[i]=a[loc]; | ||
a[loc]=temp; | ||
int main(){ | ||
int i,n,j,min,loc,temp,value; | ||
printf("enter number of number elements in array\n"); | ||
scanf("%d",&n); | ||
int arr[n]; | ||
printf("\nenter array elements"); | ||
for(i=0;i<n;i++){ | ||
scanf("%d",&value); | ||
arr[i]=value; | ||
} | ||
printf("\narray elements\n"); | ||
for(i=0;i<n;i++){ | ||
printf("%d",arr[i]); | ||
} | ||
|
||
for(i=0;i<n;i++){ | ||
min=arr[i]; | ||
loc=i; | ||
for(j=i+1;j<n;j++){ | ||
if(min>arr[j]){ | ||
min=arr[j]; | ||
loc=j; | ||
} | ||
} | ||
temp=arr[i]; | ||
arr[i]=arr[loc]; | ||
arr[loc]=temp; | ||
} | ||
|
||
printf("\nselection sorted array\n"); | ||
for(i=0;i<n;i++){ | ||
printf("%d",arr[i]); | ||
} | ||
return 0; | ||
} | ||
printf("array of the selection sort"); | ||
for(i=0;i<size;i++) | ||
printf("%2d",a[i]); | ||
getch(); | ||
} |