Question

In: Computer Science

Write a C program that asks the user to enter 15 integer numbers and then store them in the array.

Write a C program that asks the user to enter 15 integer numbers and then store them in the array. Then, the program will find the second largest element in array and its index without sorting the array. For example, In this array {-55,-2,1, 2, -3, 0, 5, 9, 13, 1, 4, 3, 2, 1, 0}, the second largest element is 9 [found at index 7].

Solutions

Expert Solution

#include

int main()
{
int arr[15], size, i;
int max1, max2;
printf("Enter 15 integers in the array: ");
for(i=0; i<15; i++)
{
scanf("%d", &arr[i]);
}
max1 = max2 =arr[0];
for(i=0; i<15; i++)
{
if(arr[i] > max1)
{
max2 = max1;
max1 = arr[i];
}
else if(arr[i] > max2 && arr[i] < max1)
{
max2 = arr[i];
}
}
printf("Second largest = %d", max2);
return 0;
}

OUTPUT:-

// If any doubt please comment


Related Solutions

in C++, Write a program that asks the user to enter 6 numbers. Use an array...
in C++, Write a program that asks the user to enter 6 numbers. Use an array to store these numbers. Your program should then count the number of odd numbers, the number of even numbers, the negative, and positive numbers. At the end, your program should display all of these counts. Remember that 0 is neither negative or positive, so if a zero is entered it should not be counted as positive or negative. However, 0 is an even number....
write a C program that asks the user to enter numbers and finds maximum among them
write a C program that asks the user to enter numbers and finds maximum among them
Write a program that asks the user to enter an array of random numbers, then sort...
Write a program that asks the user to enter an array of random numbers, then sort the numbers (ascending order), then print the new array, after that asks the user for a new two numbers and add them to the same array and keep the array organization. (c++ ) (using while and do while loops)
Write a C++ program that asks the user to enter in three numbers and displays the...
Write a C++ program that asks the user to enter in three numbers and displays the numbers in ascending order. If the three numbers are all the same the program should tell the user that all the numbers are equal and exits the program. Be sure to think about all the possible cases of three numbers. Be sure to test all possible paths. Sample Runs: NOTE: not all possible runs are shown below. Sample Run 1 Welcome to the order...
Question : Write a C program that asks the user to enter an integer between 1...
Question : Write a C program that asks the user to enter an integer between 1 and 7 that represents a weekday number (1 = Sunday, 2 = Monday , …… , 6 = Friday , 7 = Saturday) and it prints the day (i.e., Sunday, Monday, …… , Friday or Saturday). The program continuously asks the user to enter a weekday number till the user responds by ‘N’. and give me an output please use printf and scanf #include...
Write a C program that does the following: 1) Asks the user to enter an integer...
Write a C program that does the following: 1) Asks the user to enter an integer N 2) Asks the user to enter three words with at least N letters and at most 20 letters 3) Prints the first N letters from the first word 4) Prints the last N letters from the second word 5) Prints all letters in the odd position in the third word Output: Please enter an integer N: 3 Please enter a word with at...
c program Write a program that asks the user to enter a sequence of 15 integers,...
c program Write a program that asks the user to enter a sequence of 15 integers, each either being 0, 1, or 2, and then prints the number of times the user has entered a "2" immediately following a "1". Arrays are not allowed to appear in your code. Include ONLY THE SCREENSHOT OF YOUR CODE in an image file and submit the file.
Write a C++ program that asks the user to enter a series of single-digit numbers with...
Write a C++ program that asks the user to enter a series of single-digit numbers with nothing separating them. Read the input as a C-string or a string object. The program should display the sum of all the single-digit numbers in the string. For example, if the user enters 2514, the program should display 12, which is the sum of 2, 5, 1, and 4. The program should also display the highest and lowest digits in the string. It is...
Write a Java program that asks the user to enter an integer that is used to...
Write a Java program that asks the user to enter an integer that is used to set a limit that will generate the following four patterns of multiples of five using nested loops •Ascending multiples of five with ascending length triangle •Ascending multiples of five with descending length (inverted) triangle •Descending multiples of five with ascending length triangle •Descending multiples of five with descending length (inverted) triangle Use error checking to keep asking the user for a positive number until...
write a c program that asks the user to enter any two intger numbers and each...
write a c program that asks the user to enter any two intger numbers and each number consist of four digits. your program should check whether the numbers are four digits or not and in case they are not a four digit number the program should print a message and exit otherwise it should do the following print a mnew as follows    select what you want to do with the number 1-3: 1-print grreatest common divisor (gcd)of the two...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT