i want to Code a program which recives squarex and publish n numbers in descending order anyone can help me

Can you provide more information on what you want to do ?

What did you try ?

What is not working ?

1 Like

i want someting like it : input 9 1 4 5 16

output 4 3 2.1 2 1

i write this program with c++ but i need it with r prorgraming

```
#include <iostream>
using namespace std;
#define MAX 100
int main()
{
//array declaration
double arr[MAX];
int n,i,j;
int temp;
//read total number of elements to read
cout<<"Enter total number of elements to read: ";
cin>>n;
//check bound
if(n<0 || n>MAX)
{
cout<<"Input valid range!!!"<<endl;
return -1;
}
//read n elements
for(i=0;i<n;i++)
{
cout<<"Enter element ["<<i+1<<"] ";
cin>>arr[i];
}
//print input elements
cout<<"Unsorted Array elements:"<<endl;
for(i=0;i<n;i++)
cout<<arr[i]<<"\t";
cout<<endl;
for(i=0;i<n;i++)
{
arr[i] = (double) sqrt(arr[i]);
}
//sorting - Descending ORDER
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
if(arr[i]<arr[j])
{
temp =arr[i];
arr[i]=arr[j];
arr[j]=temp;
}
}
}
//print sorted array elements
cout<<"Sorted (Descending Order) Array elements:"<<endl;
for(i=0;i<n;i++)
cout<<arr[i]<<"\t";
cout<<endl;
return 0;
}
```

Hi Adam, are you just looking for R's function to sort an array (or vector in R's jargon)?

Check out sort(). And if you're looking to include those print statement I'd looking into creating a function in R.

If you're just getting started with R, welcome! Here's a handy guide

1 Like