REMOVE DUPLICATES FROM THE ARRAY IN C#

SOURCE CODE :

//programed by Paras Wadher
MCA
Nagpur university

//WAP TO REMOVE DUPLICATES FROM THE ARRAY

using System;
using System.Collections.Generic;
using System.Text;

namespace dulpicates
{
class Program
{
static void Main(string[] args)
{
int n;
Console.WriteLine(“Enter the range:=>”);
n = int.Parse(Console.ReadLine());
int[] a = new int[50];
Console.WriteLine(“Enter the array:=>”);
for (int i = 0; i < n; i++)
{
a[i] = int.Parse(Console.ReadLine());
}
for (int i = 0; i < n; i++)
{
for (int j = i + 1; j < n; j++)
{
if (a[i] == a[j])
{
a[j] = 0;
}
}
}
Console.WriteLine(“\n***Array after removing duplicates***”);
for (int i = 0; i < n; i++)
{
if (a[i] != 0)
{
Console.WriteLine(a[i]);
}
}
Console.ReadLine();
}
}
}

// **********output*********

Enter the range:=>
10
Enter the array:=>
1
2
2
3
2
323
2343545
45
45
67

***Array after removing duplicates***
1
2
3
323
2343545
45
67


Leave a Reply

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