I need help craeting a program in C that can sort these numb

I need help craeting a program in C that can sort these numbers below using array. I also need it to find the largest, smallest, and the average of the numbers. An example out put that does not include there numbers is:

The original numbers are: -391.03 833.90 -987.66 -659.06 159.69 -732.98 675.00 947.41 -13.39 -330.47 -740.21 -389.48

The sorted numbers are: -987.66 -740.21 -732.98 -659.06 -391.03 -389.48 -330.47 -13.39 159.69 675.00 833.90 947.41

The largest number is 947.41, the smallest is -987.66, and the average is -135.69.

-292.92, 809.92, 296.47, -866.93, -211.09, -448.18, -515.57, 994.76, -551.41, 135.89, 296.65, 648.94, 642.92, 508.61, -996.24, -18.25, -471.63, 404.86, -605.35, 877.32, -714.09, -220.99, -850.70, -585.50, -862.41, -881.97, 832.74, 753.35, -711.53, -273.35, -162.94, -115.49, -329.94, -4.45, 807.46, 404.42, 940.82, 458.97, -181.73, -708.12, -632.44, 660.30, 865.75, -885.09, 17.72, 281.37, 168.90, 140.41, 248.95, -183.02, -313.78, 563.56, 859.76, -194.25, -133.12, -164.48, -144.98, 997.35, -76.22, -300.38, -563.86, -585.62, 994.89, 760.84, 365.12, 106.20, 409.94, 802.34, 614.01, -423.18, 836.06, -771.80, -886.91, 252.46, -762.88, -27.31, -759.54, 130.81, -466.18, 406.02, 326.46, -239.70, 947.79, 220.05 ,-214.82, 186.22, 566.05, -185.33, 521.55 ,-88.91, -545.55, -510.18

Solution

#include<stdio.h>
#include<string.h>
#include<conio.h>
float getlargest(float arr[]);
float getsmallest(float arr[]);
float getavg(flaoat arr[]);
void main(){
int i,len=0,j;
float temp=0.0,lagest=0.0,smallest=0.0,avg=0.0;
clrscr();
float arr[5]={-11.39,384.3,22.34,2.43,0.34};
len=strlen(arr);
for(i=0;i<len;i++){
for(j=i+1;j<len;j++){
if(arr[i]>arr[j]){
temp=arr[i];
arr[i]=arr[j];
arr[j]=temp;
}
}
}
for(i=0;i<len;i++)
printf(\"%f\",arr[i]);
lagest=getlarges(arr);
smallest=getsmallest(arr);
avg=getavg(arr);
printf(\"largest is:%f\",lagest);
printf(\"smallest is:%f\",smallest);
printf(\"average is:%f\",avg);
getch();
}
float getlargest(float arr[]){
int i;
int big=arr[0];
for(int i=0;i<strleln(arr);i++)
{
if(arr[i]>big)
big=arr[i];

}
return big;
}
float getsmallest(float arr[]){
int i;
int small=arr[0];
for(int i=0;i<strleln(arr);i++)
{
if(arr[i]<small)
small=arr[i];

}
return small;
}

foat getavg(float arr[]){
int len=0,i;
float sum=0.0;
float avg=0.0;
len=strlen(arr);
for(i=0;i<len;i++){
sum+=arr[i];
}
avg=sum/len;
return avg;
}
output:

-11.39

0.34

2.43

23.34

384.3

largest is:384.3

smallest is:-11.39

average is:79.804

I need help craeting a program in C that can sort these numbers below using array. I also need it to find the largest, smallest, and the average of the numbers.
I need help craeting a program in C that can sort these numbers below using array. I also need it to find the largest, smallest, and the average of the numbers.

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site