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
Studentka2010 [4]
2 years ago
7

Write a program second.cpp that takes in a sequence of integers, and prints the second largest number and the second smallest nu

mber. Note that in the case of repeated numbers, we really mean the second largest and smallest out of the distinct numbers (as seen in the examples below). You may only use the headers: and .
Computers and Technology
1 answer:
sergey [27]2 years ago
4 0

Answer:

The program is as follows:

#include <iostream>

#include <vector>

using namespace std;

int main(){

   int n;

   cout<<"Elements: ";

   cin>>n;

   vector <int>vectnum;

   int numInp;

   for (int i = 1; i <= n; i++){        cin>>numInp;        vectnum.push_back(numInp);    }

   int big, secbig;

   big = vectnum.at(0);      secbig = vectnum.at(1);

   if(vectnum.at(0)<vectnum.at(1)){     big = vectnum.at(1);  secbig = vectnum.at(0);   }

   for (int i = 2; i< n ; i ++) {

     if (vectnum.at(i) > big) {

        secbig = big;;

        big = vectnum.at(i);

     }

     else if (vectnum.at(i) > secbig && vectnum.at(i) != big) {

        secbig = vectnum.at(i);

     }

  }

  cout<<"Second Largest: "<<secbig<<endl;

  int small, secsmall;

  small = vectnum.at(1);       secsmall = vectnum.at(0);

  if(vectnum.at(0)<vectnum.at(1)){ small = vectnum.at(0);  secsmall = vectnum.at(1);   }

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

     if(small>vectnum.at(i)) {  

        secsmall = small;

        small = vectnum.at(i);      }

     else if(vectnum.at(i) < secsmall){

        secsmall = vectnum.at(i);      }   }

  cout<<"Second Smallest: "<<secsmall;

  return 0;

}

Explanation:

See attachment for explanation

Download cpp
You might be interested in
Match the element of a presentation program to its description
lana [24]

Answer:

A) Array of buttons for<u> quick access </u>to commonly used <u>commands and tools</u>: Tool bar

That's what most people will use most of the time, to quickly perform the most common tasks.

B) <u>List of commands</u> to create, format and edit presentations: Menu Bar.

When the features listed in the tool bar aren't enough, we go to the Menu system, which lists all the features of the program.

C) <u>Provides info</u> about current slide<u> at the bottom</u> of the slide: Status Bar.

The status bar is always located at the <u>bottom of the screen</u>.

D) <u>Provides navigation</u> through the slides: Scroll bar.

Where you can scroll down and up your slides.

4 0
3 years ago
When you first open a word processor, you’ll find a ? document. A. filled B. blank C. edited
NikAS [45]
B, blank document is the answer
3 0
3 years ago
Read 2 more answers
The rubric given to them by their teacher requires that
Arte-miy333 [17]

Answer:1:navigate to the paragraph command group

2:Click the line and paragraph spacing option

3:Click the space required

Explanation:

3 0
3 years ago
I'll give brainlist to right answers
xeze [42]
I think it’s number 1. Check the answer first.
5 0
3 years ago
By definition, a computer
lapo4ka [179]

Answer has a screen

Explanation:

a computer has a screen

5 0
2 years ago
Other questions:
  • How important is technology in education? what technology-related skills can you contribute to a school district answers?
    13·1 answer
  • How neural networks impact our life??
    7·1 answer
  • Can you tell me what is rast
    5·1 answer
  • Which of these is most closely associated with system control? (1 point) (Points : 1.5) boundary
    10·1 answer
  • Lifelong learning _____. is only important for professionals with advanced degrees can be formal or informal includes formal cla
    12·1 answer
  • Which type of appliance can host several functions, such as antimalware, firewall, content filter, and proxy server
    11·1 answer
  • What will be result of below if statement.
    13·1 answer
  • (20points)
    6·1 answer
  • when working with smart which tab would provide the ability to change the shape or size of the smart art shapes
    15·2 answers
  • Task 2: Typing a School Speech
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!