Basic C Code Write a basic C code for a function which sorts

Basic C++ Code

Write a basic C++ code for a function which sorts integers of a one-dimensional array in ascending order. The array and the number of elements in it are the parameters.

Solution

#include<iostream>
using namespace std;
int main()
{
   int score[] = {50, 60, 77, 84, 39};
   int len;
   len = sizeof(array);
   cout<<\"Before Sorting\ \";
   for(i = 0; i < len; i++)
{
       cout<<\" \"<<score[i];
   }  
   sort (len, score);
  
   cout<<\"After Sorting\ \";
   for(i = 0; i < len; i++)
{
       cout<<\" \"<<score[i];
   }  
   return 0;
}
  
void sort(int m, int arr[ ])
{   
int i, j, temp;

for(i = 1; i <= m-1; i++)   
for(j = 1; j <= m-i; j++)   
if(arr[j-1] >= arr[j])
{
temp = arr[j-1];
arr[j-1] = arr[j];   
arr[j] = temp;
}   
}

Basic C++ Code Write a basic C++ code for a function which sorts integers of a one-dimensional array in ascending order. The array and the number of elements in

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site