jeudi 13 décembre 2018

c++ - a code that reads 5 decimal places and arranges it in descending order

I have a problem with how to sort the descendant of this 5th array on this line of code. Can anyone explain how it works?

    #include "stdafx.h"
    #include <iostream>
    #include <conio.h>

    using namespace std;

    void main() { float a[5] , k; int i,j ;

    for(i=0 ; i<5; i++)     cin>> a[i];

=====================these lines============================ 
for(i=0;i<4;i++)
for(j=i+1;j<5;j++)
if (a[i]<a[j])  
{ 
k=a[i];
a[i]=a[j]; 
a[j]=k;
}
=================================================


    for (i=0; i<5;i++)  cout << "      "<<a[i];

    _getch();

    }

Aucun commentaire:

Enregistrer un commentaire