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
anzhelika [568]
3 years ago
15

The process of finding the largest and smallest numbers is used frequently in computer applications. Write a C++ program that us

es a while statement to determine and print the largest and the second largest number of x integers entered by the user, where x should also be input by the user.
Computers and Technology
1 answer:
WINSTONCH [101]3 years ago
3 0

Answer:

The program to this question can be given as:

Program:

#include<iostream>  //header file

using namespace std;

int main()    //main method

{

int x[10],i,largest = 0,second_largest=0,n;  //variable

cout << "Enter Number of elements :";  //message

cin>>n;

cout << "Insert array elements :";  //message

for(i=0;i<n;i++)  //insert elements in array

{

cin >>x[i];

}

//Finding Largest element  

for(i=0;i<n;i++)

{

if (x[i]>largest)

{

largest = x[i];

}

}

//finding second largset element

for(i=0;i<n;i++)

{

if (x[i]>second_largest)

{

   if(x[i]==largest)

   {

   continue;   //Ignoring largest in order to get second largest

   }

   second_largest=x[i];

}

}

//print value

cout <<"Largest Number:"<<largest<<endl;

cout <<"Second Largest Number:"<<second_largest;

return 0;

}

Output:

Enter Number of elements :5

Insert array elements :33

45

75

87

23

Largest Number:87

Second Largest Number:75

Explanation:

In the above program firstly we define the header file then we define the main method in the main method we define the array and other variables. We first input the number for the size of the array. Then we insert array elements after inserting array elements we search the largest number and the second largest number in the array. To search the largest number in the array we use the loop. To search the first largest number we define a condition that array is greater than the largest number and store the value into the largest variable. Then we check the second largest number in the array for this we use two conditions that are array is greater than the second largest number in this we use another condition that is array is equal to the largest number. If the inner condition is true then it will move forward and end of an inner condition. In the outer condition, the value will be stored on the second_largest variable all the conditions will be done inner the loop. At the last we print values.

You might be interested in
In addition to environmental issues, what does true sustainability address?
VashaNatasha [74]

In addition to environmental issues, true sustainability addresses the preservation of social and economic resources.

Sustainability simply refers to the meeting of our needs without wastage or jeopardizing the resources being available to future generations.

<u>Sustainability</u> is vital for the protection of the<u> environment</u>, social equity, and development. When there is <em>sustainability,</em> the environment is protected and the resources are available for others.

Some examples of sustainability include avoiding wasting water, a limit on hunting activities, etc.

Read related link on:

brainly.com/question/13220961

4 0
3 years ago
Read 2 more answers
Give me your 3ds friend code :)
Karolina [17]

You can friend me mine is- 3024-6635-0458

4 0
4 years ago
How do i mark brainliest?
neonofarm [45]

Answer: There is a crown button that should pop up by the question you have asked.

Explanation: ...

8 0
3 years ago
Read 2 more answers
COMPUTER CODING
scZoUnD [109]

Answer:Maybe put in Ball.move.left.right(100)

Explanation:

If the ball should move then the code might be left and right,

I don't know if I am right but I do coding too.

3 0
3 years ago
An analyst receives an alert from the SIEM showing an IP address that does not belong to the assigned network can be seen sendin
lianna [129]

Answer: (A)  Firewall; implement an ACL on the interface

Explanation:

 According to the question, for re-mediate the issue firewall should be implemented the ACL (Access control list) on the given interface. The access control list is one of the type of logic which selectively give permission or deny the number of packet in the system which to through the interface.

Firewall is the type of device that basically examine the traffic in the network system and also make several decisions in the system. ACL is the set of rule which mainly define the route of the packet in the router interface state.

4 0
3 years ago
Other questions:
  • (PLS HELP 99 POINTS) In a paragraph of no less than 125 words, explain the three aspects involved in gaining a true appreciation
    14·2 answers
  • Document creation is a key business function because:
    6·2 answers
  • What is the program filename and extension of file explorer?
    9·1 answer
  • An EEG measures the electrical output of the brain by using sensors that are attached to someone's hands and feet. Please select
    15·2 answers
  • Which of the following is the Boolean logical operator for AND in C#?
    12·1 answer
  • With his assembly lines, Henry Ford improved what process? A. computer management B. just-in-time management C. Bessemer process
    5·1 answer
  • Write a script that will read from a file x and y data points in thefollowing format:
    9·1 answer
  • Create a winform application that lets the user enter a temperature. With a ComboBox object offer the user three choices for inp
    9·1 answer
  • Ayuda!!
    14·1 answer
  • Im going to find where u live and bring a doctor to give u a tetnus shot
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!