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
likoan [24]
3 years ago
15

Complete the given C program (prob1.cpp) to read an array of integers, print the array, and find the 2nd largest element in the

array. A main function in prob1.cpp is given to read in the array. You are to write two functions, printArray() and getElement(), which are called from the main function. printArray() outputs integers with a space in between numbers and a newline at the end. getElement() returns an integer that is the second largest element in the array. You may assume that the integers are unique.
Computers and Technology
1 answer:
labwork [276]3 years ago
5 0

Answer:

#include <stdio.h>

int getElement(int arr[], int size) {

   

   int largest2, largest = 0;

   for(int i=0; i<size; i++)

   {

       if(arr[i] > arr[largest])

       {

           largest = i;

       }

   }

   if(largest != 0)

       largest2 = 0;

   else

       largest2 = size - 1;

   for(int i=0; i<size && i != largest ;i++)

   {

       if(arr[i] > arr[largest2])

           largest2 = i;

   }

   

   return arr[largest2];

}

printArray(int arr[], int size) {

   

   printf("The array is: ");

   for(int i=0; i<size; i++)

   {

       printf("%d ", arr[i]);

   }

   printf("\n");

}

int main()

{

 

   int arr[5] = {30, 20, 5, 10, 24};

   printArray(arr, 5);

   printf("Second largest number is: %d", getElement(arr, 5));

   return 0;

}

Explanation:

Since you did not provide any code, I wrote it from the scratch. I also added the main function for you to check the result.

<em>printArray</em> function basically prints the element of the array

<em>getElement</em> function:

- Declare the two variables to hold the value for largest and second largest

- Inside the first loop, check if there is any number that is greater than largest, if yes, assign it to largest

- Inside the second for loop, check if there is any number that is greater than largest2, if yes, assign it to largest2 (Be aware that the largest we found in the first loop is excluded)

- Return the second largest

* Notice that we were able to apply this solution since the numbers are unique.

You might be interested in
For which input values will the following loop not correctly compute the maximum of the values? 1. Scanner in = new Scanner (Sys
My name is Ann [436]

Answer:

The answer is "Option d".

Explanation:

Please find the complete question in the attached file.

8 0
3 years ago
the handles the overall activity of the computer and provides services such as memory management, input/output activities, and s
Alisiya [41]

The operating system controls the overall activity of the computer and furnishes services such as memory management, input/output activities, and storage management.

<h3>What is operating system?</h3>

An operating system (OS) is the programme that controls all other application programmes in a computer after being installed into the system first by a boot programme. Through a specified application programme interface, the application programmes seek services from the operating system (API).

It controls the memory, operations, software, and hardware of the computer. You can converse with the computer using this method even if you don't understand its language. A computer cannot function without an operating system.

An operating system performs three primary tasks: managing the computer's resources, including the CPU, memory, disc drives, and printers; creating a user interface; and running and supporting application software.

Hence, The operating system controls the overall activity of the computer and furnishes services such as memory management, input/output activities, and storage management.

To learn more about operating system refer to:

brainly.com/question/19999569

#SPJ4

4 0
2 years ago
What will be the result from running the following program?
qwelly [4]

Answer:

If this is python

then you will get this from console:

Grades
100
93

82

Total
275

5 0
2 years ago
Which graph or chart shows changes in the value of data?
yKpoI14uk [10]

Answer:

Bar graph and Pie chart

3 0
3 years ago
Read 2 more answers
A hard drive that uses fde is often referred to as a(n) ____.
Sergio039 [100]

FDE stands for full disk encryption. FDE encrypts data as it is written to the disk and decrypt data as it is read off the disk. It is the simplest method of deploying encryption ,transparent to applications, databases, and users.

A hard drive that uses FDE is often referred to as a self-encrypting hard drive. correct answer: B

6 0
3 years ago
Other questions:
  • Angela's ready to get started with her first Smart Display campaign, but her account isn't yet eligible due to not having enough
    11·1 answer
  • Create a file with a 20 lines of text and name it "lines.txt". Write a program to read this a file "lines.txt" and write the tex
    12·1 answer
  • How do you find the exterior angle measure of any regular polygon? (The degree in which to turn the turtle to draw a shape)
    10·1 answer
  • PLEASE HELP!!!!!!!!!!!
    15·2 answers
  • What is an identifier? Give an example of an identifier.
    13·1 answer
  • Operational feasibility, which refers to user acceptance and support, as well as management acceptance and support, is also know
    9·1 answer
  • "_____ devices improve memory by encoding items in a special way."
    13·1 answer
  • Given two integer variables distance and speed, write an expression that divides distance by speed using floating point arithmet
    13·1 answer
  • How do you delete your brainly account
    6·1 answer
  • Can someone please help me with this .
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!