top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration

Facebook Login
Site Registration

can someone make unique number function, function prints all unique numbers in array?

+1 vote
posted Apr 17, 2017 by Leon Martinović

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote

We can use two nested loops. The outer loop picks an element one by one and inner loop checks if the element is present on left side of it. If present, then ignores the element, else prints the element.

C++ Implementation

#include <iostream>
#include <algorithm>

using namespace std;

void printUniqueIntegres(int arr[], int n)
    // Pick all elements one by one
    for (int i=0; i<n; i++)
        // Check if the picked element is already printed
        int j;
        for (j=0; j<i; j++)
           if (arr[i] == arr[j])

        // If not printed earlier, then print it
        if (i == j)
          cout << arr[i] << " ";

int main()
    int arr[] = {6, 10, 15, 14, 19, 1120, 14, 6, 10};
    int n = sizeof(arr)/sizeof(arr[0]);
    printUniqueIntegres(arr, n);
    return 0;

Credit: geeksforgeeks

answer Apr 17, 2017 by Salil Agrawal
Contact Us
+91 9880187415
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Karnataka INDIA.