Untitled
unknown
plain_text
a year ago
1.5 kB
9
Indexable
#include <iostream> using namespace std; class arrayop { private: int arr[100]; public: void get_input(int n) { for(int i = 0;i<n;i++) { cin>>arr[i]; } } void large_small(int n) { int large=arr[0]; int small=arr[0]; for(int i=1;i<n;i++) { if(large<arr[i]) large=arr[i]; } for (int i=1;i<n;i++) { if(small>arr[i]) small=arr[i]; } cout<<"The largest element is:"<<large<<endl; cout<<"The Smallest element is:"<<small<<endl; int temp = large; int second_large=arr[0]; if(second_large==large) second_large=arr[1]; for(int i=1;i<n;i++){ if(arr[i]==temp){ continue;} else { if(second_large<arr[i]) second_large=arr[i]; } } cout<<"The second largest Element is: "<<second_large<<endl; int temp1 = small; int second_small=arr[0]; if(second_small==small) second_small=arr[1]; for(int i=1;i<n;i++){ if(arr[i]==temp1){ continue;} else { if(second_small>arr[i]) second_small=arr[i]; } } cout<<"The second smallest is: "<<second_small<<endl; } }; int main() { int n; cout<<"Enter the size of the array:"; cin>>n; arrayop myobj; myobj.get_input(n); myobj.large_small(n); return 0; }
Editor is loading...
Leave a Comment