0% found this document useful (0 votes)
6 views6 pages

RECw 1

Uploaded by

Senthur
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views6 pages

RECw 1

Uploaded by

Senthur
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Ex.

no:01 Searching algorithm (Linear & Binary search)


using Array
Date:02.07.24

Aim:

Program:
1.)C++ Program to find the second minimum element and second maximum element
in an array by Linear search
2.)C++ Program to count the number of unique elements in an array of n elements.
3.) C++ Program to search the number of occurrences of a given element in an
array.
4.) Given an array arr[] of length N, the task is to find the length of the longest
subarray which consists of consecutive numbers in increasing order from the array.

Algorithm:
Code:
1.)
#include<iostream>
using namespace std;
int main()
{
int a[10],i,j,t=0,b[10];
cout<<”Enter input:”;
for(i=0;i<10;i++)
{cin>>a[i];}
for(j=0;j<10;j++)
{for(i=j+1;i<10;i++){
if(a[j]>a[i]){
t=a[j];
a[j]=a[i];
a[i]=t;}}}
for(i=0;i<10;i++)
{cout<<a[i]<<" ";}
cout<<”Max”<<a[8];
cout<<”Min”<<a[1];
return 0;}

Output:
2.)
#include<iostream>
using namespace std;
int main()
{
int a[5],i,j,b,c=0;
cout<<"enter 5 elements";
for(i=0;i<5;i++)
{cin>>a[i];}
for(i=0;i<5;i++)
{b=0;
for(j=0;j<5;j++)
{ if(a[i]==a[j])
{b++;}}
if(b==1)
{c++;}}
cout<<"no of unique elements"<<c;
return 0;}

Output:
3.)
#include<iostream>
using namespace std;
int main()
{
int a[5],i,j,b=0,c;
for(i=0;i<5;i++)
{cin>>a[i];
}
cout<<"enter element to be counted";
cin>>c;
for(i=0;i<5;i++)
{
if(a[i]==c)
b++;
}
cout<<endl<<b;
getch();}

Output:
4.)
#include <bits/stdc++.h>
using namespace std;
int maxsubarrint arr[],int n)
{
int maxi =0;
for (int i=0;i<n-1;i++){
int ct =1,j;
for (j=i;j<n;j++){
if (arr[j+1]==arr[j]+1){
ct++;}
else{break;}}
maxi = max(maxi, ct);
i = j;}
return maxi;}
int main()
{
int n = 11;
int arr[] = { 1, 3, 4, 7, 8, 4,
2, 9, 5, 6, 12 };
cout << maxsubarrarr, n);
return 0;}

Output:

Result:
The above programs are executed successfully.

You might also like