Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Must be coded with C: Write a program first to ask the user input a positive int

ID: 3600937 • Letter: M

Question

Must be coded with C:

Write a program first to ask the user input a positive integer n to show how many numbers he/she wants to input later. Then use a loop to get the n positive integer inputs. After that, output the second maximum number. Name your code Hw4 q4 code.c. Example Hints and Inputs: (purple texts are what the program should print on the screen to instruct the users, the black texts are what the users type in) Input the number of integers you want to input: 5 Input Integer 1: 1 Input Integer 2: 7 Input Integer 3: 3 Input Integer 4: 8 Input Integer 5: 2 Example Outputs:

Explanation / Answer

#include<stdio.h>

int main(){

int inputarray[50],inputSize,i,highest,secondHighest;

printf("Input the number of Integers you want to Input:");

scanf("%d",&inputSize);

for(i=0;i<inputSize;i++)

{

printf("Input Integer %d:", i+1);

scanf("%d",&inputarray[i]);

}

highest = -1;

secondHighest = -1;

for (i = 0; i < inputSize ; i++)

{

if (inputarray[i] > highest)

{

secondHighest = highest;

highest = inputarray[i];

}

else if (inputarray[i] > secondHighest && inputarray[i] != highest)

{

secondHighest = inputarray[i];

}

}

printf("%d", secondHighest);

return 0;

}