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 does a professional programmer usually do first to gain an understanding of a problem?
ElenaW [278]
The correct answer to your question is:

Professional programmers work directly with, and interview customers to find out what the problem is.
6 0
2 years ago
Read 2 more answers
What impact did congress declaration on copyrighting sound recordings have on home recording and record sales
cricket20 [7]

Answer:

By the late 1980s, several manufacturers were prepared to introduce read/write digital audio formats to the United States. These new formats were a significant improvement over the newly introduced read-only (at the time) digital format of the compact disc, allowing consumers to make perfect, multi-generation copies of digital audio recordings. Most prominent among these formats was Digital Audio Tape (DAT), followed in the early 1990s by Philips' Digital Compact Cassette (DCC) and Sony's Minidisc.

DAT was available as early as 1987 in Japan and Europe, but device manufacturers delayed introducing the format to the United States in the face of opposition from the recording industry. The recording industry, fearing that the ability to make perfect, multi-generation copies would spur widespread copyright infringement and lost sales, had two main points of leverage over device makers. First, consumer electronics manufacturers felt they needed the recording industry's cooperation to induce consumers – many of whom were in the process of replacing their cassettes and records with compact discs – to embrace a new music format. Second, device makers feared a lawsuit for contributory copyright infringement.[1]

Despite their strong playing hand, the recording industry failed to convince consumer electronics companies to voluntarily adopt copy restriction technology. The recording industry concurrently sought a legislative solution to the perceived threat posed by perfect multi-generation copies, introducing legislation mandating that device makers incorporate copy protection technology as early as 1987.[2] These efforts were defeated by the consumer electronics industry along with songwriters and music publishers, who rejected any solution that did not compensate copyright owners for lost sales due to home taping.[3]

The impasse was broken at a meeting in Athens in 1989, when representatives from the recording industry and the consumer electronics industry reached a compromise intended to enable the sale of DAT recorders in the United States. Device manufacturers agreed to include SCMS in all consumer DAT recorders in order to prevent serial copying. The recording industry would independently pursue legislation requiring royalties on digital audio recording devices and media.[4]

A year later the songwriter Sammy Cahn and four music publishers, unhappy with the absence of a royalties provision in the Athens agreement, filed a class action copyright infringement suit against Sony.[5] The plaintiffs sought declaratory and injunctive relief that would have prevented the manufacture, importation or distribution of DAT recorders or media in the United States. The suit brought Sony to heel. In July 1991, Sony, as part of larger agreement between the recording industry and consumer electronics makers, agreed to support legislation creating a royalty scheme for digital media. In exchange, Cahn and the publishers agreed to drop the suit.[6]

With all the major stakeholders satisfied, the bill easily passed both houses of Congress. President George H. W. Bush signed the AHRA into law in 1992 proclaiming " S. 1623 [AHRA] will ensure that American consumers have access to equipment embodying the new digital audio recording technology. It also protects the legitimate rights of our songwriters, performers, and recording companies to be fairly rewarded for their tremendous talent, expertise, and capital investment. This will be accomplished by fairly compensating these artists for the copying of their works and by creating a system that will prevent unfettered copying of digital audio tapes."

3 0
3 years ago
Read 2 more answers
Question 2 of 10
Roman55 [17]

Answer:

C

Explanation:

correct answer

3 0
3 years ago
This is a quick and easy program that will let you practice the basics of the switch statement. You will ask the user to enter a
Nikolay [14]

Answer:

Explanation:

oof okay

5 0
3 years ago
A network router connects multiple computers together and allows them to send messages to each other. If two or more computers s
Sedbober [7]

Answer:

C = M0(M1+M2+M3)+M1(M2+M3)+M2M3 is the equation which suits

Explanation:

From the given data we can state that we need to activate only one product i.e 1------>activated 0-------->means inactivated and also only one slot is activated at a time.The resultant will be no data inputs n control bits and 2 to the power n output bits.

8 0
3 years ago
Other questions:
  • Computers spend most of their time in loops, so multiple loop itera- tions are great places to speculatively find more work to k
    10·1 answer
  • In three to five sentences, describe how you can organize written information logically and sequentially
    8·1 answer
  • Use ________ resolution when recording human speech in an audio file.
    14·1 answer
  • You are logged in as a user with limited system privileges, you are the linux system administrator and you have the password to
    5·1 answer
  • The type of database that is connected by a company's local area networks is a(n:
    11·1 answer
  • Which key combination will allow users to move to the top of a document?
    15·1 answer
  • What was the first computer programming language?
    7·2 answers
  • True or false: The objective of an Enterprise Resource Planning (ERP) system is to create a customized software program that int
    10·1 answer
  • When you open a program, the hard drive
    7·1 answer
  • The web design teams of a company are working on designing websites for various companies, Pick the ideas that employ proper use
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!