Marufcse

Design a program that will find Biggest & Smallest Value with Position from a data set using user de

Nov 24th, 2021 (edited)
19
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.09 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. int Biggest (int arr[],int num)
  4. {
  5.     int i, max,pos;
  6.     max = arr[0];
  7.     for(i=1;i<num;i++)
  8.     {
  9.         if(arr[i]>max)
  10.             pos=i;
  11.             max =arr[i];
  12.  
  13.     }
  14.     cout<<"Biggest  element in the array is: " << max <<" And Position Is: "<<pos<<"\n";
  15. return 0;
  16. }
  17.  
  18. int smallest(int arr[],int num)
  19. {
  20.     int i, min,pos=0;
  21.     min = arr[0];
  22.     for(i=1;i<num;i++)
  23.     {
  24.         if(arr[i]<min)
  25.             pos=i;
  26.             min =arr[i];
  27.  
  28.     }
  29.     cout<<"Smallest  element in the array is: " << min <<" And Position Is: "<<pos<<"\n";
  30.     return 0;
  31. }
  32. int main()
  33. {
  34.     int i, array[50], size,selector;
  35.  
  36.  
  37.     cout<<"Input number of elements in array\n";
  38.     cin>>size;
  39.  
  40.     cout<<"Enter "<< size << " integers\n";
  41.     for(i=0;i<size;i++)
  42.     cin>>array[i];
  43.     cout<<"Please Select an Option which item you want to find\n"<<endl;
  44.     cout<<"Press 1 For Find Biggest Value \n Press 2 For Smallest Value "<< endl;
  45.     cin>>selector;
  46.     if(selector==1){
  47.     Biggest (array,size);
  48.  
  49.     }
  50.     else if(selector==2){
  51.  
  52.  
  53.     smallest(array,size);
  54.     }
  55.     else{
  56.         cout<<"please press 1/2"<<endl;
  57.     }
  58. return 0;
  59. }
  60.  
Add Comment
Please, Sign In to add comment