Eliminate Duplicate Elements

QUESTION

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.\n\nInput Format:\nInput consists of n+1 integers where n is the number of elements in the list. The first integer corresponds to n. The remaining n integers correspond to the elements in the list.\nAssume that the maximum value of n is 100\n\nOutput Format:\nOutput consists of n integers on separate lines\n.

“TESTCASE_1”: “5\n2 3 4 3 6\n###—###SEPERATOR—###—\n2\n3\n4\n6”, “TESTCASE_2”: “15\n1 2 3 4 5 1 2 3 4 5 1 2 3 4 5\n###—###SEPERATOR—###—\n1\n2\n3\n4\n5”, “TESTCASE_3”: “0\n###—###SEPERATOR—###—\n0”, “TESTCASE_4”: “0\n###—###SEPERATOR—###—\n0”, “TESTCASE_5”: “0\n###—###SEPERATOR—###—\n0

ANSWER

  #include<stdio.h>
int main(){
  int n,a[100],i,c,j;
  scanf("%d",&n);
  for(i=0;i<n;i++)
    scanf("%d",&a[i]);
  
  for(i=0;i<n;i++)
  {
    c=0;
    for(j=0;j<i;j++)
    {
      if(a[i]==a[j]){
        c=1;
        break;
      }
    }
    if(c==1)
      continue;
    else
      printf("%d\n",a[i]);
  }
  
  return 0;
}
Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.

Powered By
100% Free SEO Tools - Tool Kits PRO