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
What is network topology? PLZZZ HURRY
Mashcka [7]

Answer:

Network topology is the arrangement of the elements (links, nodes, etc.) of a communication network. Network topology can be used to define or describe the arrangement of various types of telecommunication networks, including command and control radio networks, industrial field busses and computer networks.

7 0
3 years ago
Which subunit of a heterodimeric cdk is the regulatory subunit?
Lemur [1.5K]
The answer is cyclin subunit
8 0
2 years ago
1. How is the pronoun their used in the second sentence?
bezimeni [28]

The pronoun is used in the second sentence as To link a subject with the word(s)that describes it.

<h3>What is a pronoun?</h3>

This is known to  be a word or phrase that is said to be used to replace a noun or noun phrase.

Note that in the above sentence, the pronoun " their" is used to The pronoun is used in the second sentence as To link a subject with the word(s)that describes it as it tells more about service project.

Learn more about pronoun from

brainly.com/question/395844

#SPJ1

5 0
1 year ago
I NEED HELP WITH SOME PROBLEM ON BRAINLY PLEASE HELP
docker41 [41]
What is the issue,please tell me so i can know ur question
6 0
3 years ago
A researcher plans to identify each participant in a certain medical experiment with a code consisting of either a single letter
trapecia [35]

Answer:

5 Letters

Explanation:

So we need 12 distinct codes made of a single letter or a pair of letters.

What would be the least number of letters?

Lets try with 3 letters A, B and C

The possible combinations are: A, B, C, AB, AC, BC

These are 6 codes and we need 12 so lets try more A, B, C and D

The possible combinations are: A, B, C, D, AB, AC, AD, BC, BD, CD

These are 10 codes and we need 12 so lets try more A, B, C, D and E

The possible combinations are:

A, B, C, D, E, AB, AC, AD, AE, BC, BD, BE, CD, CE, DE

Finally we got 15 distinct codes which are more than 12 so the least number of letters needed are 5.

Using formula:

Four letters = 4C1 + 4C2 = 4 + 6 = 10

Five letters = 5C1 + 5C2 = 5 + 10 = 15

5 0
2 years ago
Other questions:
  • A company has developed a business-critical system for its core automation process with a software vendor. Which of the followin
    12·1 answer
  • Not providing guarding or fall protection for workers on a 25-foot scaffold. The resulting fall would most likely end in death,
    6·1 answer
  • What is required for sitting with your seatbelt on while driving?
    7·1 answer
  • Computer software licensed under exclusive legal right of the copyright holder with the intent that the licensee is given the ri
    6·1 answer
  • Which of the following is NOT a strength of monetary policy?
    15·1 answer
  • Write a C program that right shifts an integer variable 4 bits. The program should print the integer in bits before and after th
    15·1 answer
  • Who elso does their online school in their bed cause i do
    7·2 answers
  • Question 1 (1 point)
    13·1 answer
  • If any one has mincraft on ps4 bedrock we can finish building a BIG city world all we need to put is a shop and money dispensers
    8·2 answers
  • Sftp uses which mechanism to provide security for authentication and data transfer?
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!