Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int Biggest (int arr[],int num)
- {
- int i, max,pos;
- max = arr[0];
- for(i=1;i<num;i++)
- {
- if(arr[i]>max)
- pos=i;
- max =arr[i];
- }
- cout<<"Biggest element in the array is: " << max <<" And Position Is: "<<pos<<"\n";
- return 0;
- }
- int smallest(int arr[],int num)
- {
- int i, min,pos=0;
- min = arr[0];
- for(i=1;i<num;i++)
- {
- if(arr[i]<min)
- pos=i;
- min =arr[i];
- }
- cout<<"Smallest element in the array is: " << min <<" And Position Is: "<<pos<<"\n";
- return 0;
- }
- int main()
- {
- int i, array[50], size,selector;
- cout<<"Input number of elements in array\n";
- cin>>size;
- cout<<"Enter "<< size << " integers\n";
- for(i=0;i<size;i++)
- cin>>array[i];
- cout<<"Please Select an Option which item you want to find\n"<<endl;
- cout<<"Press 1 For Find Biggest Value \n Press 2 For Smallest Value "<< endl;
- cin>>selector;
- if(selector==1){
- Biggest (array,size);
- }
- else if(selector==2){
- smallest(array,size);
- }
- else{
- cout<<"please press 1/2"<<endl;
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment