Programming Examples
Cpp program to find whether it is a unique array or not
Write a Cpp program to find whether it is a unique array or not
Solution
#include<iostream>
using namespace std;
int main(){
int num[5],a,flag=0;
cout<<"Enter 5 elements in an array";
for(a=0;a<5;a++)
{
cin>>num[a];
}
for(a=0;a<5;a++)
{
for(int b=a+1;b<5;b++)
{
if(num[a]==num[b])
{
flag=1;
//cout<<num[a];
break;
}
}
}
if(flag!=1)
{
cout<<"Unique array ";
}
else
{
cout<<"Not a Unique array ";
}
return 0;
}
Output
Enter 5 elements in an array
1
2
3
3
4
Not a unique array