program to sort an array

#include <iostream>
using namespace std;

// funtion to sort the array

void sortingarr(int arr[],int size){
for (int i = 0; i < size-1; i++)
{
int minIndex = i;
for (int j = i+1; j < size; j++)
{
if (arr[j]<arr[minIndex])
{
minIndex = j;
}
}
swap(arr[minIndex],arr[i]);
}
}

int main(){
int arr[5]={34,4,56,78,3};
sortingarr(arr,5);

}

Comments

Popular posts from this blog

swapping the alternate values in given array's element ! 17/11/2022

Learning stage | c++ programs

c++ basic question