Removing the duplicate number in array

February 22, 2019
Removing the duplicate number in array
#include <iostream>
#include <cstring>
using namespace std;
int main()
{
    int array[6]={1,1,2,2,3,4};
    int array2[6]={0};
    int n,p;
    p = array[0];
    cout<<p;
    for(int i = 1; i<6;i++)
    {
         n = array[i];
         if(p != n){
            array2[i]=n;
         }
         p=n;
    }
    for(int i = 1; i<6;i++)
    {
        if(array2[i]>0)
         cout<<" "<<array2[i]<<" ";
    }


    return 0;
}

No comments:

'; (function() { var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true; dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js'; (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq); })();
Powered by Blogger.