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


Latest Current Affairs 2024 Online Exam Quiz for One day Exam Online Typing Test CCC Online Test 2024 Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Best Java Training Institute in Prayagraj (Allahabad) Best Python Training Institute in Prayagraj (Allahabad) O Level Online Test in Hindi Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Sarkari Naukari Notification Best Website and Software Company in Allahabad Sarkari Exam Quiz