Zero Duplicates

Write a program that will read in a list of numbers and will then print out the same list except numbers that have already been printed will be printed as a zero instead.


Sample Input :

4

3

2

1

4

Sample Output:

3

2

1

0

code:

#include<stdio.h>
int main()
{
    int n,i,j;
    int a[100],c;
    scanf("%d",&n);
    if(n<=100)
    {
        for(i=0;i<n;i++)
        {
            scanf("%d",&a[i]);
        }
        for(i=0;i<n-1;i++)
        {
            c=a[i];
            for(j=i+1;j<n;j++)
            {
                
                if(c==a[j]&&c!=0)
                {
                    a[j]=0;
                }
            }
        }
        for(i=0;i<n;i++)
        {
            if(a[i]!=-1)
            {
                printf("%d\n",a[i]);
            }
        }
    }
    return 0;
}

Leave a Reply

Your email address will not be published. Required fields are marked *