#include <iostream>
using namespace std;
void NumberOfOccur(int arr[],int n,int num){
int count=0;
for(int i=0;i<n;i++){
if (arr[i]==num)
count++;
}
cout<<"\nNumber of occurance of "<<num<<" is "<<count;
}
int RemoveDublicates(int arr[],int n){
if (n==0 || n==1)
return n;
int tp[n];
int j = 0;
for (int i=0; i<n-1; i++)
if (arr[i] != arr[i+1])
tp[j++] = arr[i];
tp[j++] = arr[n-1];
for (int i=0; i<j; i++)
arr[i] = tp[i];
return j;
}
void SecondLargestSmallest(int arr[],int n){
}
void searchElement(int arr[],int n){
}
void sort(int arr[],int n){
}
int main()
{
int n=10;
int arr[n]={1, 1, 2, 2, 3, 4, 4, 4, 5, 5};
cout<<"Choose an operation to perform:\n";
cout<<"1. Number of occurrences of a given Number in the array:\n";
cout<<"2. Remove the duplicate elements in the array:\n";
cout<<"3. Second largest and Second smallest element in the array:\n";
cout<<"4. Search an element in an array:\n";
cout<<"5. Sorting the array elements in ascending or descending based on user choice:\n";
int c;
cin>>c;
if (c==1){
int num;
cout<<"\nEnter a number: ";
cin>>num;
NumberOfOccur(arr,n,num);
}
else if(c==2){
int f=RemoveDublicates(arr,n);
for (int i=0; i<n; i++)
cout << arr[i] << " ";
}
else if(c==3){
SecondLargestSmallest(arr,n);
}
else if(c==4){
searchElement(arr,n);
}
else if(c==5){
sort(arr,n);
}
else{
cout<<"\nInvalid choice";
}
return 0;
}
Comments
Leave a comment