Skip to content
This repository has been archived by the owner on Jan 15, 2023. It is now read-only.

Create SwapSecondBiggestAndSecondElementInArray.cpp #681

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions CPP/SwapSecondBiggestAndSecondElementInArray.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include<iostream>
using namespace std;
int main ()
{
int A[10], n, i, j, x;
cout << "Enter size of array : ";
cin >> n;
cout << "Enter elements of array - ";
for (i = 0; i < n; i++)
cin >> A[i];
for (i = 0; i < n; i++)
{
for (j = i + 1; j < n; j++)
{
if (A[i] < A[j])
{
x = A[i];
A[i] = A[j];
A[j] = x;
}
}
}
cout << "Second largest number - " << A[1]<<endl;
cout << "Second smallest number - " << A[n - 2];
return 0;
}