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
You must signal ___ before any turn or lance change ?
Alexeev081 [22]

Answer:

Your turning signal, or blinker

3 0
3 years ago
Read 2 more answers
What is the best free game designing program for windows
Nadusha1986 [10]
Python, Unity 3D, C++Notepad
8 0
3 years ago
assume for arithmetic, load/store, and branch instructions, a processor has CPIs of 1, 12, and 5, respectively. Also assume that
KonstantinChe [14]

Answer:

1 PROCESSOR :

(1 × 2.56 × 10^9) + (12 × 1.28 × 10^9) + (5 × 2.56 × 10^8) / 2 GHz = 9.6 s

2 PROCESSORS :

(1×2.56×10^9)+(12×1.28×10^9)/0.7×2 + (5 × 2.56 × 10^8) / 2 GHz = 7.04 s

Speed -up is 1.36

4 PROCESSORS :

(1×2.56×10^9)+(12×1.28×10^9)/0.7×4 + (5 × 2.56 × 10^8) / 2 GHz = 3.84 s

Speed -up is 2.5

5 PROCESSORS :

(1×2.56×10^9)+(12×1.28×10^9)/0.7×8 + (5 × 2.56 × 10^8) / 2 GHz = 2.24 s

Speed -up is 4.29

Explanation:  

The following formula is used in this answer:

EXECUTION TIME = CLOCK CYCLES / CLOCK RATE

Execution Time is equal to the clock cycle per clock rate

7 0
3 years ago
The critical path of a network is the A. shortest time path through the network. B. path with the most activities. C. longest ti
S_A_V [24]

Answer: Option [C] : The longest time path through the network.

Explanation:

The critical path of a network is the longest time path through the network.

8 0
3 years ago
What does the green light mean?<br>And does it have a red light?
Rom4ik [11]
Green light usally mean its charged and red means its dead
5 0
3 years ago
Read 2 more answers
Other questions:
  • What are some common characteristics of jobs in this career cluster? check all that apply
    10·2 answers
  • Net Worth is equal to assets minus liabilities. Which event will have the greatest impact (positive or negative) on one's net wo
    5·1 answer
  • What is the highest education degree available at a community college
    14·1 answer
  • Commercial websites have domain names so that users can easily access the web pages by typing the domain names instead of the IP
    12·1 answer
  • The ability to keep web page visitors at your site is called _______.
    11·1 answer
  • Write a C++ program that stores the integers 50 and 100 in variables and stores the sum of these two in a variable named total.
    11·1 answer
  • You are the administrator for a small network with several servers. There is only one printer, which is centrally located. Altho
    10·1 answer
  • A proposal is also known as a
    14·2 answers
  • Mike logged into a shopping website and entered his username and password. Which protocol will the website use to verify his cre
    15·1 answer
  • When creating a report,you can mske groups and subgroups by?​
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!