Skip to content

MyUstaadG

Learn to Serve

  • Computer Science
    • Software
    • Computer Tips
    • Coding
      • Conditional Structures Exercises
      • Loops Exercises
      • Arrays Exercises
      • Python Exercises
    • Microsoft Office
      • MS Excel
      • MS Word
  • Videos
    • Funny Videos
    • Health and Fitness Videos
    • PUBG Videos
    • Technology Videos
  • News
  • Funny
  • Memes
  • Playwright Tutorials
  • Tutorials
  • Toggle search form

Write a program that inputs 10 numbers into an array and finds out the second largest value from that array.

Posted on October 16, 2021 By myustaadg.com
Spread the love

Write a program that inputs 10 numbers into an array and finds out the second largest value from that array.

So let’s Write Code:

Introduction to C++ Programming | Download and Install Dev C++ Compiler

Let’s build logic First:

Algorithm for code:

  • Step 1: Start
  • Step 2: Declare an array and variables largest, sec_largest, and i.
  • Step 3: Take Inputs form user.
  • Step 4: Set largest and sec_largest = arr[0].
  • Step 5: Compare all array elements one by one and store second largest number in sec_largest.
  • Step 6: Print sec_largest
  • Step 7: End Program

Code:

Write a program that inputs 10 numbers into an array and finds out the second largest value from that array.

#include<iostream>
using namespace std;
main()
{
int ar[10], largest, sec_largest, i;
for(i=0; i<=9; i++)
{
cout<<"Enter value in element "<<i<<" ? ";
cin>>ar[i];
}
sec_largest = largest = ar[0];
for(i = 1; i<=9; i++)
{
if(largest < ar[i])
largest = ar[i];
if(sec_largest < ar[i] && largest > ar[i])
sec_largest = ar[i];
}
cout<<"Second Largest value in array is : "<<sec_largest<<endl;
}

Hope You will learn Something. Happy Coding.

Visit my YouTube Channel as Well๐Ÿ˜‡ https://www.youtube.com/watch?v=JuIHQ9cLSEw&list=PLbIhkHxfUIItTdcyCb34uRIrPJbXBndIl&index=4

Click on the below Links for more Programming Exercises:

Conditional Structure Exercises: ๐Ÿ‘‰https://myustaadg.com/category/programming-exercises/conditional-structures-exercises/

Array Exercises: ๐Ÿ‘‰https://myustaadg.com/category/programming-exercises/arrays-exercises/

Arrays Exercises, Programming Exercises Tags:Array Exercises, Array exercises in C++, array in Object oriented programming, array in OOP, Arrays in C++, c program to find the greatest among ten numbers, c++ program to find second largest element, c++ program to find second largest number among 3 numbers, C++ program to find the greatest among ten numbers, cpp program to largest and second largest elements in array, how do i find the second largest number in c++, how do you find the largest 10 numbers in c ++, how do you find the largest and second largest number in c ++, how to write 10 input numbers and find the greatest one using while loop, write a c program to find second largest element in an unsorted array, write a c++ program to enter 10 numbers into an array and find the second largest element, write a c++ program to find second largest element in an unsorted array, Write a program that inputs 10 numbers into an array and finds out the second largest value from that array., write a program that will find the second largest element in a given array of integers

Post navigation

Previous Post: Write a program that inputs marks of N students and finds out the grade of each student.
Next Post: Write a program to input an array of 10 elements from the user and count the number of odd numbers and display it.

More Related Articles

Write a program that initializes the values in the one-dimensional array and computes the sum of even values. Arrays Exercises
Write a program using two arrays and enter values in 1st array. The program should copy the values of the 1st array to 2nd array. Arrays Exercises
Write a program that initializes values 2, 6, 3, 5, 4 and 7 in one-dimensional array and computes the factorial. Arrays Exercises
Write a program that inputs values into an array and finds the smallest and largest value from it. Arrays Exercises
Write a program that initializes an array with the number of days of different months. It inputs the number of month and displays the number of days of the entered month. Arrays Exercises
Write a program that input user name and displays on the screen in python | Python Programming Programming Exercises

Copyright © 2022 MyUstaadG.

Powered by PressBook Blog WordPress theme