C Program to Print the distinct elements in an array

                    To Print the distinct elements in an array


C Program

#include <stdio.h>
 
int main()
{
  int n, a[100], b[100], count = 0, c, d;
 
  printf("Enter number of elements in array\n");
  scanf("%d", &n);
 
  printf("Enter %d integers\n", n);
 
  for (c = 0; c < n; c++)
    scanf("%d", &a[c]);
 
  for (c = 0; c < n; c++)
  {
    for (d = 0; d < count; d++)
    {
      if(a[c] == b[d])
        break;
    }
    if (d == count)
    {
      b[count] = a[c];
      count++;
    }
  }
 
  printf("Array obtained after removing duplicate elements:\n");
 
  for (c = 0; c < count; c++)
    printf("%d  ", b[c]);
 
  return 0;
}

Comments

Popular posts from this blog

C Program to Print a trapezium pattern

C Program to Print Pattern 1*2*3*4 9*10*11*12 13*14*15*16 5*6*7*8

Glimpse Of SPYDER | Mahesh Babu | A R Murugadoss | Rakul Preet Singh | Harris Jayaraj | #SPYDER Trailer , Teaser