1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Sedaia [141]
2 years ago
14

Write a C++ program to find if a given array of integers is sorted in a descending order. The program should print "SORTED" if t

he array is sorted in a descending order and "UNSORTED" otherwise. Keep in mind that the program should print "SORTED" or "UNSORTED" only once.
Computers and Technology
1 answer:
LenKa [72]2 years ago
4 0

Answer:

The cpp program for the given scenario is as follows.

#include <iostream>

#include <iterator>

using namespace std;

int main()

{

   //boolean variable declared and initialized  

   bool sorted=true;

   //integer array declared and initialized

   int arr[] = {1, 2, 3, 4, 5};

   //integer variables declared and initialized to length of the array, arr

   int len = std::end(arr) - std::begin(arr);

       //array tested for being sorted

    for(int idx=0; idx<len-1; idx++)

    {

        if(arr[idx] < arr[idx+1])

           {

               sorted=false;

            break;

           }

    }

    //message displayed  

    if(sorted == false)

     cout<< "UNSORTED" <<endl;

 else

    cout<< "UNSORTED" <<endl;

return 0;

}

OUTPUT

UNSORTED

Explanation:

1. An integer array, arr, is declared and initialized as shown.

int arr[] = {1, 2, 3, 4, 5};

2. An integer variable, len, is declared and initialized to the size of the array created above.

int len = std::end(arr) - std::begin(arr);

3. A Boolean variable, sorted, is declared and initialized to true.

bool sorted=true;  

4. All the variables and array are declared inside main().

5. Inside for loop, the array, arr, is tested for being sorted or unsorted.  The for loop executes over an integer variable, idx, which ranges from 0 till the length of the array, arr.

6. The array is assumed to be sorted if all the elements of the array are in descending order.

7. If the elements of the array are in ascending order, the Boolean variable, sorted, is assigned the value false and for loop is exited using break keyword. The testing is done using if statement.

8. Based on the value of the Boolean variable, sorted, a message is displayed to the user.

9. The program can be tested for any size of the array and for any order of the elements, ascending or descending. The program can also be tested for array of other numeric data type including float and double.

10. All the code is written inside the main().

11. The length of the array is found using begin() and end() methods as shown previously. For this, the iterator header file is included in the program.

You might be interested in
Complete each sentence to describe different elements of an Excel worksheet.
barxatty [35]

Answer:

Answer is - cell, - column, - string value

Explanation:

  • <em>Cell - this is often referred to as the intersection of a single row and column.  </em>
  • <em>Column - this is a group of cells which are represented vertically.  </em>
  • <em>String - these are values that are inside the cell which are represented through texts or group of letters including acceptable symbols and characters.</em>
7 0
2 years ago
Read 2 more answers
You would like to enter a formula that subtracts the data in cell B4 from the total of cells B2 and B3. What should the formula
anastassius [24]

Answer:

=b2 b3-b4 or something close to that, I hope this helps ^^

Explanation:

6 0
3 years ago
What is the best definition of a network?
Cerrena [4.2K]

Answer:

C is the answer to this question.

3 0
2 years ago
Read 2 more answers
In today's digital marketplace, the line between retailer and distributor has become less distinct.
jenyasd209 [6]

Answer:

The answer you're looking for is True - The line between retailer and distributor has become less distinct.

Explanation:

5 0
3 years ago
What's a big question or problem in the tech field you'd like to solve and why?
aleksandrvk [35]

A big question or problem in the tech field that i would like to solve is Data security.

<h3>What is Data security ?</h3>

Data security  can be regarded as process of protecting data from unauthorized user as well as protection from  data corruption .

I will like to solve this problem because as advances in technology, the data of individual or organization is not been total secured and this is posing so much loss to individuals.

Data security are;

  • data encryption
  • hashing
  • tokenization

Learn more about Data security at;

brainly.com/question/17493537

5 0
2 years ago
Other questions:
  • What are the three fundamental elements of an effective security program for information systems?
    11·2 answers
  • If I put a short clip from a copyrighted video to Facebook and make it only viewable to friends, is that illegal?
    12·1 answer
  • If you see ________________________ in a cell, it means the column is not wide enough to display the cell content. Select one: a
    15·1 answer
  • Which of the following is a valid variable name? a. salesTax b. input-string c. 25Percent d. double
    8·1 answer
  • What is the output of the following program when the method is called with 4?
    11·1 answer
  • Question 2 (5 points)
    12·1 answer
  • describe a situation in which peer pressure could cause a serious problem for safe driving, and how you could resist the peer pr
    8·2 answers
  • SOLVE IN C:
    10·1 answer
  • What is computer specification
    15·1 answer
  • 23. Convert the following to Megabytes<br> a) 2GB<br> b) 2056 Bytes-
    8·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!