Skip to content

Instantly share code, notes, and snippets.

@imsushant12
Created April 20, 2021 16:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save imsushant12/2295418a5ee2e7ec9c659239ef1666e9 to your computer and use it in GitHub Desktop.
Save imsushant12/2295418a5ee2e7ec9c659239ef1666e9 to your computer and use it in GitHub Desktop.
#include<bits/stdc++.h>
using namespace std;
void findLargestSmallest(int a[] , int n)
{
int large = a[0];
int small = a[0];
for(int i=0 ; i<n ; i++)
{
//when a[i] is smaller than small
if(a[i] < small)
{
if(a[i] < small)
small = a[i];
else if(a[i+1] > large)
large = a[i];
}
}
cout<<"Smallest element = " <<small<<endl;
cout<<"Largest element = " <<large<<endl;
}
int main()
{
int a[] = { -8 , 10 , 2 , 15 , 13 , 0 };
int n = sizeof(a) / sizeof(a[0]);
findLargestSmallest(a , n);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment