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]
2 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]2 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
There are local administrators for each of the departments, excluding the IT. These local administrators will use the local admi
torisob [31]

Answer:

Listed below are the few ways Linux Server can be secured

1. Group policies: This is a way to ensure security by applying group policies and permissions both on the group level and the files level. Through proper permission configuration we can easily restrict other users from accessing those files and directories.

2. Implementation of the firewall: Implementing firewall in each of the Linux server will definitely help in securing your machine from outside threats. Iptables will help in filtering the network traffic that are entering into the system and even going out of the system.

3.Enabling SELINUX: Enabling SELINUX is another way to secure your system especially a Linux Server. Selinux is a powerful security that checks and allows applications to run into the system. It won't allow any untrusted application to run into the system.

6 0
3 years ago
President Roosevelt's Fireside Chats were:
larisa86 [58]
C. Entertaining radio shows that families listened to in the evening. He did these chats to inform the public on what he was going to do about the problems facing the public.
3 0
2 years ago
Read 2 more answers
Courts are struggling with the privacy implications of GPStracking. In 2009, New York’s highest court held that policeofficers m
aniked [119]

Answer:

warrant

Explanation:

New York State's highest court ruled in 2009 that tracking a person via the global positioning system (GPS) without a warrant violated his right to privacy.

6 0
3 years ago
Design a software system for a bookstore that keeps an inventory of two types of books: Traditional books and books on CD. Books
Sophie [7]

Answer:

Explanation:

a. In this scenario, the best solution would have an Object of Traditional Books, CD, Music, Bookstore and Customer.

b. All five objects would be able to be called by the main program loop and the Customer Object would call upon and use either the Books or CD object, While the Bookstore object would call upon all of the other objects.

c. Both the Bookstore object and Customer object will "have" other objects as the Bookstore needs to hold information on every Book or CD in the Inventory. While the Customer object would call upon the Book and CD object that they are purchasing.

d. The Music Object will extend the CD object and use information on the CD object as its parent class.

e. Since the Music Object extends the CD object it is also considered a CD since it is in CD format like the Books on CD and therefore is both objects.

8 0
3 years ago
In which of the following locations can you edit all of the Properties of a PowerPoint file?
Lapatulllka [165]
Access the File<span> menu, choose </span>Info Pane<span> to get to </span>Backstage view, you can see Properties on t<span>he area on the right side </span>of the current PowerPoint presentation.  <span>Within the </span>Properties<span> pane click the </span>Show All Properties<span>  option , T</span><span>his will displays properties such as </span>Size<span>, the number of </span>Slides<span>,  </span>Hidden Slides<span>, the number of </span>Multimedia Clips, etc.  Some of the entries are editable w<span>ithin the  </span>Properties pane, and some are not. Just move your mouse cursor over any detail of a property. The editable sections will change the cursor into edit mode.  
6 0
3 years ago
Other questions:
  • Assign testResult with 1 if either geneticMarkerA is 1 or geneticMarkerB is 1. If geneticMarkerA and geneticMarkerB are both 1,
    11·1 answer
  • Troubleshooting a printer that does not work includes a. connecting the printer to your computer b. checking to see if there is
    13·1 answer
  • Which method can be used to write data to a text file opened with the BufferedWriter object outfile?
    9·1 answer
  • All 24-point fonts take up the same amount of space on a slide. True False
    7·2 answers
  • How do you change the name on your brainly account?
    12·1 answer
  • Vicky is investigating multiple hacking attempts on her cloud-based e-commerce web servers. She wants to add a front-end securit
    5·1 answer
  • Use the syntax SELECT ________ (expression) [Column Name] to limit the result set to the number of rows defined by the expressio
    10·1 answer
  • Which of the following database object hold data?
    13·2 answers
  • How will you maintain electrical tools and equipment?
    12·2 answers
  • The scope of a temporary table is limited to what?
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!