Created
April 20, 2021 16:08
-
-
Save imsushant12/2295418a5ee2e7ec9c659239ef1666e9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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