Without Pointers c++ query

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
//print repeated elements from an array
#include<iostream>
using namespace std;

int main()
{
    int p,n;

    cout<<"enter no. of elements in array: "<<endl;
    cin>>n;
    int a[n],b[n];
    int z=0;
    cout<<"enter elements of array:"<<endl;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    for(int j=0;j<n;j++)
    {
        for(int k=j;k<=n;k++)
        {
            if(j==k)
            {
                continue;
            }
            else if(a[j]==a[k])
            {
                b[z]=a[j];
                ++z;
                a[k]=a[k+1];        //deleting the array element which repeats
                a[n-1]=0;           //settng last element as 0
                --n;                //reducing the size of array
                break;
            }
            int d=z;
            if(b[j]==b[k])
            {
                b[j]=b[j+1];
                b[n-1]=0;
                n--;
            }
        }
    }
    if(z==0)
    {
        cout<<"No Elemnts in the array is repeated"<<endl;
    }
    else
    {
        cout<<"repeated elements are: "<<endl;
        for(p=0;p<z;p++)
            {
                cout<<b[p]<<" ";
            }
    }

return 0;
}



How to fine tune this program so as it displays correct output? When we enter 3 similar elements it repeats itself twice and also has problem reading the last element.
Thanks
Here we go again:
1
2
    cin>>n;
    int a[n],b[n];

http://www.cplusplus.com/forum/general/73552/
http://www.cplusplus.com/forum/unices/56833/

BTW, do you mind telling us what the program ought to be doing?
Topic archived. No new replies allowed.