Question
Asked Sep 18, 2019
1 views

In C++

Sort an array from largest to smallest (you may use one of the sorts we did, you just have to change it so that it goes from largest to smallest instead).

check_circle

Expert Answer

Step 1

Program:

//include the required header files
#include<iostream>
using namespace std;

//definition of main method
int main ()
{
//declare the required variables
int arr[5];
int i, j, temp;

//get the input numbers from the user
cout<<"Enter 5 numbers : ";
for (i = 0; i < 5; ++i)
cin>>arr[i];
 
//sort the numbers
for (i = 0; i < 5; ++i)
{
for (j = i + 1; j < 5; ++j)
{
if (arr[i] < arr[j])
{
//swap the numbers
temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
}
//display sta...

Want to see the full answer?

See Solution

Check out a sample Q&A here.

Want to see this answer and more?

Solutions are written by subject experts who are available 24/7. Questions are typically answered within 1 hour.*

See Solution
*Response times may vary by subject and question.
Tagged in

Engineering

Computer Science

Related Computer Science Q&A

Find answers to questions asked by student like you
Show more Q&A
add
question_answer

Q: Code should be in C++ Absolute Value Template: Write a function template that accepts an argument an...

A: Since Function Templates are used to handle all possible data types you can say generic data type at...

question_answer

Q: The symmetric difference of two sets S1 and S2 is defined as S1 ⊝ S2 = {x : x ∈ S1 or x ∈ S2, but x ...

A: Solution:Given that,The symmetric difference between two sets such as “S1” and “S2” can be expressed...

question_answer

Q: Consider the following grammar in BNF (start symbol is ) Which of the following sentences are in the...

A: Backus-Naur Form (BNF):BNF is a formal mathematical method to define the syntax of the programming l...

question_answer

Q: Programming in C language.

A: Note:The below given program has been compiled using "repl.it" online compiler.

question_answer

Q: 4.23 (Financial application: payroll) Write a program that reads the following information and print...

A: C code#include&lt;stdio.h&gt;#include&lt;string.h&gt; int main(){char employeeName[20]="";double hou...

question_answer

Q: do big data could replace the artistic vision of a creative director? and why?

A: Justification:“Yes”, big data replace the artistic vision of a creative director.

question_answer

Q: Write a PL/SQL block to retrieve and display the students enrolled in a course.

A: Click to see the answer

question_answer

Q: Write a class in java with the name AgeMessages , which does the following:a. Ask the user to enter...

A: The algorithm for the program would be as below:Declare one float variable for accepting user inputP...

question_answer

Q: Use Eclipse for do this program. Show the output of the following statements.a) System.out.printf("a...

A: The program has the following algorithm:a) The statement print the amount in floating point and expo...