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
What level of system and network is required for cui
galben [10]

Answer:

CUI will be classified at a “moderate” confidentiality level and follow DoDI 8500.01 and 8510.01 in all DOD systems. Non-DoD systems must provide adequate security with requirements incorporated into all legal documents with non-DoD entities following DoDI 8582.01 guideline

Explanation:

6 0
3 years ago
Isabela wants to add an image to her presentation. Which tab should she use?
Tresset [83]

Answer:

I believe its insert

Explanation:

because when u insert an image ur adding it

6 0
4 years ago
You have been tasked to set up an authentication server on a dmz that will allow only users from a partner company. what kind of
Lapatulllka [165]

The question above has multiple choices as follows;

a. Internet

<span> b. Intranet <span> c. Extranet <span> d. World Wide Web
Correct answer is C. Extranet
<span>You are able to use an Extranet to securely share part of a business’s operation with vendors, suppliers, customers, partners or any other business organization.  We can also view an extranet as an intranet extended to users outside the company.</span> </span></span></span>




7 0
3 years ago
A ___________ is similar to an intranet in that it uses internet technologies, but is developed for users outside the organizati
Vanyuwa [196]
The blank is extranet
I hope this helped!
6 0
3 years ago
You notice that it’s very easy to confuse medications at the community health center where you’re working. They are lined up on
Bezzdna [24]

Answer:

The answer is design systems to prevent errors.

Explanation:

This system helps to prevent medication errors with resultant patient harm and cost. The best would be if the community health center could afford systems that use information technology  such as computerized physician order entry, automated dispensing, barcode medication administration, among other technological solutions.

8 0
4 years ago
Other questions:
  • ¿Cómo es la onda percibida por un osciloscopio cuando hablamos de sonido? ¿Qué parámetros podemos observar en ella?
    15·1 answer
  • Direct messages are the only private forms of communication on Twitter. True False
    10·1 answer
  • Select the focus questions that emphasizes what is more important: (Select all that apply) a.What needs to be relegated to the b
    8·1 answer
  • How would you define media literacy?
    12·1 answer
  • Students who finish their homework after school are meeting a. intrapersonal and short-term goals b. normative and short-term go
    13·2 answers
  • As technology advances, does technology become more of less complex?
    14·1 answer
  • Suppose your training examples are sentences (sequences of words). Which of the following refers to the j^th word in the i^th tr
    15·1 answer
  • You are writing a program using the Java language. Which of the following is a requirement of Java syntax?
    6·1 answer
  • Examples of structures that can store homogeneous data element​
    14·1 answer
  • Hiding/masking personal identifiers from a data set, so that the data set can never identify an individual, even if it is correl
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!