“Algorithme de tri de sélection en C” Réponses codées

Sélection de sélection en C

#include "stdio.h"
void main(){
    int n,arr[100],i,j;
    printf("Enter the size of array");
    scanf("%d",&n);
    printf("Enter the elements of the array");
    for(int i=0;i<n;i++)
    {
        scanf("%d",&arr[i]);
    }
    int y;
    for(int j=0;j<n;j++)
    {
        for(int i=j+1;i<n;i++)
        {
            if(arr[i]<arr[j])
            {
                y=arr[i];
                arr[i]=arr[j];
                arr[j]=y;
            }
        }
    }
    printf("Correct Order:");
    for(i=0;i<n;i++)
    {
        printf("%d,",arr[i]);
    }
}
Healthy Hare

tri de sélection

def ssort(lst):
    for i in range(len(lst)):
        for j in range(i+1,len(lst)):
            if lst[i]>lst[j]:lst[j],lst[i]=lst[i],lst[j]
    return lst
if __name__=='__main__':
    lst=[int(i) for i in input('Enter the Numbers: ').split()]
    print(ssort(lst))
Ranger

Algorithme de tri de sélection en C

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <stdio.h>
int main()
{
int a[100], n, i, j, position, swap;
printf("Enter number of elementsn");
scanf("%d", &n);
printf("Enter %d Numbersn", n);
for (i = 0; i < n; i++)
scanf("%d", &a[i]);
for(i = 0; i < n - 1; i++)
{
position=i;
for(j = i + 1; j < n; j++)
{
if(a[position] > a[j])
position=j;
}
if(position != i)
{
swap=a[i];
a[i]=a[position];
a[position=swap;
}
}
printf("Sorted Array:n");
for(i = 0; i < n; i++)
printf("%dn", a[i]);
return 0;
}
Shovon

Réponses similaires à “Algorithme de tri de sélection en C”

Questions similaires à “Algorithme de tri de sélection en C”

Plus de réponses similaires à “Algorithme de tri de sélection en C” dans C

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code