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
vivado [14]
3 years ago
12

Write a program that reads a list of integers, and outputs the two smallest integers in the list, in ascending order. The input

begins with an integer indicating the number of integers that follow.Ex: If the input is 5 10 5 3 21 2, the output is:2 3 You can assume that the list of integers will have at least 2 values.To achieve the above, first read the integers into a vector.Hint: Make sure to initialize the second smallest and smallest integers properly.
Computers and Technology
1 answer:
kompoz [17]3 years ago
8 0

Answer:

Following are the program in the C++ programming Language.

//header files

#include <iostream>

#include <vector>

using namespace std;//name space

// define main method

int main()

{

//set integer variables

int size, num;

//get input the size of the list

cout<<"Enter size of list: ";

cin >> size;

//set integer type vector variable

vector<int> vecs;

//Set the for loop

for (int index = 0; index < size; ++index)

{//get elements of the list from the user

cout<<" :";

cin >> num;

//push back the elements of the list

vecs.push_back(num);

}

//storing the first two elements in variable

int n = vecs[0], n1 = vecs[1], current , temp;

//set if conditional statement

if (n > n1)

{

//perform swapping

temp = n;

n = n1;

n1 = temp;

}

//Set for loop

for (int index = 2; index < size; ++index)

{

//store the value of the vector in the variable

current = vecs[index];

//set if conditional statement

if (current < n)

{

//interchange the elements of the variable

n1 = n;

n = current;

}

else if(current < n1)

{

n1 = current;

}

}

//print the value of first two smallest number.

cout <<"\n" <<n << " " << n1 << endl;

return 0;

}

<u>Output:</u>

Enter size of list: 5

:10

:5

:3

:21

:2

2 3

Explanation:

Here, we define the required header files and namespace then, we define "main()" function inside the main function.

  • Set two integer data type variable "size", "num".
  • Print message and get input from the user in variable  "size".
  • Then, we set integer vector type variable "vecs".
  • Set the for loop to get the number of input in the variable "num" from user.
  • Then, we push back the elements of the list and store first two elements of the list in the variable "n", "n1".
  • Set the conditional statement to perform swapping.
  • Define the for loop to store the list of the vector in the integer type variable "current".
  • Finally, we print the value of the two smallest numbers of the list.
You might be interested in
Which statement reflect a culture that value collectivism
Morgarella [4.7K]

Answer: To be honest i believe its D. All of the above reflect collectivism

hope this helps :)

8 0
4 years ago
What is the name for the last word on a dictionary page?
kakasveta [241]

Answer:

bbbbbbbbbbbbbbbbbbbbbbbb

Explanation:

bbbbbbbbbbbbbbbbbbbbbbbbb

8 0
3 years ago
VOTE: STARWARS, STAR TREK, MARVEL, STRANGER THINGS. OR IT ?
Gennadij [26K]
I'd say stranger things or it lol
5 0
3 years ago
Read 2 more answers
Identify the correct way to cite the Occupational Outlook Handbook's "How to Become a Dentist" web page.
quester [9]

Answer:

C."How to Become a Dentist." Occupational Outlook Handbook. Bureau of Labor Statistics and US Department of Labor, 29 March 2012. Web. 1 May 2013.

Explanation:

When citing an online publication without a known author, the title of the article is first stated and encapsulated in italics. This is then followed by the name of the website or book. The organization responsible for the write-up is indicated. A comma separates the name of the organization and the date when the article was written. 'Web' is written to show that the material was obtained online. Finally, the date that tells when the article was retrieved is noted.

This guideline applies to both the Modern Language Association and the American Psychological Association citation styles.

6 0
3 years ago
Read 2 more answers
The length of time that a slide appears in a power point presentation before automatically advancing to the next slide can be se
vivado [14]
The length of time that a slide appears in a power point presentation before automatically advancing to the next slide can be set in the <span> the Transitions tab, then from Timing section, and enable After option and then enter the time interval.</span>
8 0
3 years ago
Other questions:
  • One main advantage of CD-ROMs is that
    14·1 answer
  • Which of the following is not one of the five major areas to include in your notes organizer?
    15·2 answers
  • Which of the following is an example of batch processing?
    14·1 answer
  • Create a jQuery ready listener that updates the options within the element with ID toCurrency such that: The first element is: S
    12·1 answer
  • Write a Python program that asks the user for a positive, odd value. Once the value is validated determine if the number is Prim
    11·1 answer
  • Explain the effects of disposing electronic equipments to the environment ​
    13·1 answer
  • Can someone please help me with this ,it is my assignment of technology and agriculture year 8
    5·1 answer
  • What are web protocols.
    14·2 answers
  • Doctrine Creative is a video production company with its own file server within its business office. The company needs to be abl
    8·2 answers
  • What component of a change management program includes final testing that the software functions properly
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!