//sort_desc
#include <iostream>
using namespace std;
int main()
{
int n; //size of list
int i,j; //for loops for reading, swapping etc
double temp; //swapping
cout<<"Enter the size of the list"<<endl;
cin>>n;
cout<<"Enter the elements of the list\n";
double a[n]; //the list of no.s to be sorted
for (i=0;i<n;i++) //reading the elements
{
cin>>a[i];
}
for (i=0;i<n;i++) //sorting
{
for (j=i;j<n;j++)
{
if (a[i]<a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
cout<<"\nThe sorted list is \n";
for (i=0;i<n;i++)
{
cout<<a[i]<<endl;
}
return 0;
}
I’m a physicist specializing in computational material science with a PhD in Physics from Friedrich-Schiller University Jena, Germany. I write efficient codes for simulating light-matter interactions at atomic scales. I like to develop Physics, DFT, and Machine Learning related apps and software from time to time. Can code in most of the popular languages. I like to share my knowledge in Physics and applications using this Blog and a YouTube channel.
[wpedon id="7041" align="center"]
