In: Computer Science
Write a program in C that sorts 3 given numbers, defined as (a,b,c) from highest to lowest.
I already have this code finding the maximum. Need to just add the sorting code onto it.
int A, B, C;
A = 4;
B=3;
C=7;
Max = A
If (B > max)
{
Max = B;
}
Else if (c > max)
{
Max = c;
}
#include <stdio.h>
void main()
{
int arr1[100];
int n, i, j, tmp;
printf("\n\nsort elements of array in descending order :\n");
printf("----------------------------------------------\n");
printf("Input the size of array : ");
scanf("%d", &n);
printf("Input %d elements in the array :\n",n);
for(i=0;i<n;i++)
{
printf("element - %d : ",i);
scanf("%d",&arr1[i]);
}
for(i=0; i<n; i++)
{
for(j=i+1; j<n; j++)
{
if(arr1[i] < arr1[j])
{
tmp = arr1[i];
arr1[i] = arr1[j];
arr1[j] = tmp;
}
}
}
printf("\nElements of array is sorted in descending order:\n");
for(i=0; i<n; i++)
{
printf("%d ", arr1[i]);
}
printf("\n\n");
}
Sort the elements