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
Suppose that the domestic production of computer games creates enjoyment for those who play the games. Domestic production of co
kirill [66]

Answer:

a

Explanation:

Based on the information provided within the question it can be said that the best possible policy to encourage this would be to impose tariffs on computer game imports. This would force company's to begin domestic production of computer games in order to continue making the profits from the domestic market as opposed to losing out on all of the opportunities that the domestic market offers them.

6 0
3 years ago
Your program is going to compare the distinct salaries of two individuals for the last 5 years. If the salary for the two indivi
kirza4 [7]

In python:

i = 1

lst1 = ([])

lst2 = ([])

while i <= 5:

   person1 = int(input("Enter the salary individual 1 got in year {}".format(i)))

   person2 = int(input("Enter the salary individual 1 got in year {}".format(i)))

   lst1.append(person1)

   lst2.append(person2)

   i += 1

if sum(lst1) > sum(lst2):

   print("Individual 1 has the highest salary")

else:

   print("Individual 2 has the highest salary")

This works correctly if the two individuals do not end up with the same salary overall.

4 0
3 years ago
According to your textbook, which of the following is a consequence of the quick development of new technologies in the digital
kramer

Answer:

E. Traditional leaders in communication have lost some control over information                                                              

Explanation:

Due to the quick development of new technologies like Internet, cable etc, traditional leaders in communication have lost some of their control over information. This means that the technological advancement is disruptive for traditional leaders. Following examples are given to elaborate the consequences of advancement in new technology in digital era.

With the establishment of new channels like CNN, Fox News and internet bloggers, the old television network news shows like ABC, NBC lost their audiences.

Email technology has taken on some of the postal service's responsibilities and outperforms attempts to control communication outside national borders. This replaced the postal mail which used to take months to reach the destination.

The Internet and social media websites are transforming the way in which we access and interact with media culture. Before internet most people would watch popular TV shows in  at the time they originally aired it. This  scheduling gave common media interactions at specific times within our society. We still watch these TV shows but now we watch them at our own ease through websites. Using You tube we can upload our own media instead of viewing mainstream television.

8 0
3 years ago
In which type of attack do you get malicious code in links from seemingly reliable websites?
natali 33 [55]

I think it is C. cross-site scripting

6 0
3 years ago
As part of their extensive kitchen remodel, the Lees told their electrical contractors that they would need plenty of outlets fo
Vanyuwa [196]

The kind of wire and circuit breaker are:  grounding wire such as fairly large bare copper wire.

<h3>What is the best wire for the above?</h3>

A 20A, 120V small-appliance branch circuit is known to be  used in the case above.

Note that Electric range circuits needs about 50-amp, 240-volt made for circuit that is said to supplies the power to the range or oven via  a 6-3 electrical wire.

Learn more about circuit breaker from

brainly.com/question/8976395

#SPJ1

5 0
2 years ago
Other questions:
  • Write a loop that reads positive integers from standard input and that terminates when it reads an integer that is not positive.
    10·1 answer
  • Software design and implementation are interleaved activities. The level of detail in the design depends on the type of system b
    5·1 answer
  • What is the advantage of using Mail Merge Wizard when creating a mail merge?
    12·2 answers
  • 7. Which innovation in video games do you think has been most significant? Include at least one way that innovation affects the
    6·1 answer
  • Rick is linking different pages in his website. Match the value of the attribute to its meaning to enable Rick to choose the mos
    13·1 answer
  • /*Implement a class Address . An address has a house number, a street, an optional
    5·1 answer
  • Effective scrum masters apply which coaching behavior
    5·1 answer
  • Name:
    11·1 answer
  • Which of the following describe the characteristics of a good logo? Choose all that apply. It is a complex design It is memorabl
    12·1 answer
  • what option can be used to create vpn connections that can be distributed to users' computers so that vpn clients do not have to
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!