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
What term describes a wireless network topology in which access points work as peer devices on the same network?
kumpel [21]
Mesh WLAN wireless mesh network WMN describes a wireless network topology in  access points work as peer devices on the same network.
<span />
7 0
3 years ago
the function must find the substrings of s that start with a vowel and end with a consonant, then print the alphabetically first
PolarNik [594]

According to the parameters given in the questions above, the alphabetically lowest and highest substrings that start with a vowel and end with a Consonant is given below.

<h3>What is the determined substrings described above?</h3>

The determined substring is given by the following:

def findSubstrings(s):

   sub_strings_list=[]    #the required substrings list

   vowels=['a','e','i','o','u']    #vowels list

   for i in range(0,len(s)):    

       for j in range(i+1,len(s)+1):

           sub_string=s[i:j]    #slicing the original string into substring

           #checking whether the substring starts with a vowel and ends with a consonant

           if(sub_string[0] in vowels and sub_string[-1] not in vowels):    

               if(sub_string not in sub_strings_list):    #checking if the substring is already in the list

                   sub_strings_list.append(sub_string)    #if all conditions are satisfied adding the substring to the list

   sub_strings_list.sort()    #sorting the list alphabetically

   print(sub_strings_list[0])    #printing the first substring in the list

   print(sub_strings_list[-1])    #printing the last substring in the list

s=input()

findSubstrings(s)

Learn more about substrings:
brainly.com/question/21306076
#SPJ4

Full Question:

Consider a string, s — An alphabetically-ordered sequence Of Of s would be {"a", "ab•, "abc • , "bcu, If the sequence is reduced to only those substrings that start with a vowel and end with a consonant, the result is Cab", •abc"}. The alphabetically first element in this reduced list is •ab", and the alphabetically last element is "abc'. As a reminder:

Vowels: a, e, i, o, and u.

Consonants: b, c, d, f, g, h, i, k, l, m, n, p, q, r, s, t, v, w, x, y, and z.

For a given string, determine the alphabetically lowest and highest substrings that start with a vowel and end with a Consonant.

7 0
2 years ago
Describing the technologies used in diffrent generation of computer​
Rama09 [41]

Answer:

1940 – 1956: First Generation – Vacuum Tubes. These early computers used vacuum tubes as circuitry and magnetic drums for memory. ...

1956 – 1963: Second Generation – Transistors. ...

1964 – 1971: Third Generation – Integrated Circuits. 1972 – 2010: Fourth Generation – Microprocessors.

4 0
3 years ago
What is the alternative name of home page ?​
maks197457 [2]

Answer:

Home page is also known as start page

Explanation:

6 0
3 years ago
Read 2 more answers
We are just beginning to study branch instructions, but they are actually quite easy to understand. In a branch instruction, a t
AURORKA [14]

Answer:

Code is given as below:

Explanation:

globl main

   main:

       li $v0, 4      

       la $a0, prompt

       syscall

       li $t0, 0      #count for the loop to get two integers

   getnum:

       li $v1, 5   #read integer

       syscall

       addi $t0, $t0, 1    #increment the counter

       ble $t0, 2, getnum        

   printnum:  

       bgez $v0,syscall1

       bgez $v1,syscall1        #load address of num to print

       

       li $v0, 10

       syscall

.data

   data1: .word 0x63f2e3

   data2: .word 0x9100ab72

   prompt:

       .asciiz "Enter 2 numbers:"

4 0
3 years ago
Other questions:
  • When saving a memo you created in Word, which one of the following extensions is automatically assigned to the document?
    13·1 answer
  • How it print media used? ​
    9·1 answer
  • Why would a brokered CD pay more than a regular CD?
    13·1 answer
  • If you owned an online clothing company and you only had the resources to run one social media campaign, which platform would yo
    14·1 answer
  • In the cis configuration, the methyl groups are placed _____.
    8·2 answers
  • Which of the following is an automated or manual file that stores information about data elements and data characteristics such
    6·1 answer
  • Does using interior lighting help improve a drivers visibility at night
    11·1 answer
  • Why does my inbox keep getting notifications and then disappearing?
    15·2 answers
  • What is the most popular monitor​
    11·1 answer
  • Type the correct answer in each box. Spell all words correctly, and use numerals instead of words for numbers. If necessary, use
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!