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
professor190 [17]
3 years ago
5

Write a function that takes an array of integers and its size as parameters and prints the two largest values in the array. In t

his question, the largest value and the second largest value cannot be the same, even if the largest value occurs multiple times.
Computers and Technology
1 answer:
ivolga24 [154]3 years ago
3 0

Answer:

Following are the program in c++ language  

#include <iostream> // header file

using namespace std; // namespace

void largest(int a[], int size); // function declaration

int main() // main method

{

int arr[30],n,count1=0; // variable declaration

cout<<" enter the size elements in array:";

cin>>n; // read the input by user

cout<<"enter array elements:";

for(int k=0;k<n;k++) // iterating over the loop

cin>>arr[k]; // read the elements in the array

largest(arr,n); // calling function largest

return 0;

}

void largest(int a[], int n1) // function definition

{

int i, maximum, second,count=0; // variable declaration

if(n1<2) // checkiing the condition

{

cout<<"invalid input"; // print the message

return;

}

else

{

maximum =INT8_MIN; // store the minimum value of an object

second=INT8_MIN; //store the minimum value of an object

for(i = 0;i<n1; i ++) // iterating over the loop

{

if (a[i]>maximum) // comparing the condition

{

second = maximum; // store the maximum value in the second variable

maximum = a[i];

count++; // increment the count

}

else if (a[i] > second && a[i] != maximum)

{

second = a[i];

count++;

}

}

}

if(count<2)

{

cout<<"Maximum value:"<<maximum; // display the maximum value

cout<<" all the value are equal";

}

else

{

cout<<"Maximum value:"<<maximum; // display the maximum value

cout<<"Second largest:"<<second;// display the  second maximum value

}

}

Output:

enter the size elements in array:4

enter array elements:5

47

58

8

Maximum value:58 Second largest:47

Explanation:

Following are the description of program

  • In this program, we create a function largest which calculated the largest and the second largest element in the array.
  • Firstly check the size of elements in the if block. If the size is less then 2 then an invalid messages will be printed on console otherwise the control moves to the else block.
  • In the else block it stores the minimum value of an object in a maximum and second variable by using INT8_MIN function. After that iterating the loop and find the largest and second-largest element in the array .
  • In this loop, we used the if-else block and find the largest and second-largest element.
  • Finally, print the largest and second-largest elements in the array
You might be interested in
5. Why are female fans particularly valuable to the sports industry? Cite two<br> specific reasons.
shusha [124]

Answer:Females make up a large part of the market. The female fans often times spend more on things and have a greater amount of it, so if they are able to target them, they have a gained a large amount of the market

Explanation:

hope it helps

7 0
3 years ago
Which software programs should students avoid using to create and submit course work? (Choose all that apply). Word, Pages, Numb
Aleksandr [31]

Answer:

The answer to this question is given below in the explanation section.

Explanation:

You can submit your course work most often in a Word document. Because in the word document, you can insert text, numbers, images, charts whatever you want such as required for writing a book- easily.

The correct options to this question, that you should need to avoid using to create and submit course work are pages, numbers, and keynote.

Because while submitting the course work, you need to submit a complete word document, it is not required to you that you have to submit numbers, pages, or keynotes along with the course assignment. You can create a course assignment or project document in word and submit to your respective teacher. However, you can not create your course work using keynotes or pages, etc as given in the question.

3 0
3 years ago
Which UML relationships should be used between a subclass and a superclass? For example, suppose there is an interface or abstra
victus00 [196]

Answer:

C. Generalization

Explanation:

The relationship between subclass and superclass is generalization. For example there will be generalization between the class Employee and class HourlyEmployee which inherits from it. All the other options are not suitable.

8 0
3 years ago
What three values must be added to the ipv4 properties of a nic in order for a computer to have basic connectivity with the netw
Y_Kistochka [10]
1. The IP address

2. Subnet mask

3. Default gateway address

It’s values should be added to the NIC properties in order for the computer to have basic network connectivity. This can be done either statically or dynamically with DHCP. An additional value that should be present if the computer is to be used to connect to the Internet is the DNS server value. A computer automatically attempts to locate a DHCP server if configured to do so. A DHCP server address is not used. Finally, NAT is configured on a router, not on a computer host, and speed and duplex settings are NIC hardware settings and not IPv4 properties of the NIC.
8 0
2 years ago
What is the meaning of HML​
trapecia [35]

Answer:

Explanation:

Hit my line

4 0
2 years ago
Read 2 more answers
Other questions:
  • A customer states that when she removes the printed pages from her laser printer output tray, the black ink smears all over her
    10·1 answer
  • Select one of the following strategies: active listening, sandwich technique, constructive feedback. in 2-5 paragraphs, define a
    11·1 answer
  • In a _____ network, each device on the network is attached to a central server. If the server fails, then the other devices will
    8·1 answer
  • Which one is not the part of motherboard ?<br>O Registers<br>O<br>Bus<br>O<br>Port<br>O<br>none​
    14·1 answer
  • 2. Used to drive in or remove screws that fasten electrical wires or other electrical accessories. A. Pliers C. Screwdrivers B.
    15·1 answer
  • Write a for loop with a range function that prints the following output. Name the target variable number. 0 1 2 3 4 5
    6·1 answer
  • Lasses give programmers the ability to define their own types. <br><br> a. True<br> b. False
    10·1 answer
  • You have an audio that contains one pause for 0.2 seconds and another one for 0.6 seconds. When do you need to create a new segm
    5·1 answer
  • In which situation is coauthoring of presentations primarily utilized?
    13·2 answers
  • Bob The Penguin is a real you-tuber, and he plays Mine-craft. Who is his owner?
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!