Input
required to input in two sequences. first sequence is the user will input the # of items which should be greater than 1 and not be greater than 30. If the input is outside the range display "OUT OF RANGE". After validating that the range is valid, the user moves on to entering the next sequence. second sequence will require the user to input the numbers.
Out
Once all the numbers are entered, the program will simply get the largest and smallest number from the second sequence. In addition, it will also count the number of times the largest number or smallest number occurred. If the user entered the same numbers in the second sequence, the program will display the largest number and the # of times it is repeated but will display "Smallest number is the same as the largest number." for the smallest number.
In
8
8 7 6 5 4 3 2 1
Out
8:1x
1:1x
15
-1 -2 -5 -1 -5 -1 -5 -2 -1 -2 -1 -5 -1 -2 -1
-1:7x
-5:4x
20
9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9
9:20x
Smallest number is the same as the largest number.
Source code
#include <iostream>
using namespace std;
int main()
{
  int n;
   cout<<"In\n";
  cin>>n;
  int arr[n];
  for(int i=0;i<n;i++){
    cin>>arr[i];
  }
  int max=arr[0];
  int min=arr[0];
  Â
  for(int i=0;i<n;i++){
    if(arr[i]>max)
      max=arr[i];
    if(arr[i]<min)
      min=arr[i];
  }
  Â
  int count_occr_max=0;
  int count_occr_min=0;
  Â
  for(int i=0;i<n;i++){
    if(arr[i]==max)
      count_occr_max++;
    if(arr[i]==min)
      count_occr_min++;
    Â
  }
  cout<<"Out\n";
  cout<<max<<":"<<count_occr_max<<"x\n";
  cout<<min<<":"<<count_occr_min<<"x\n";
  return 0;
}
Sample run 1
Sample run 2
Comments
Leave a comment