Delete Duplicate Elements in an Array : C Program

Computer Science » C Program » Delete Duplicate Elements in an Array 

Program :

#include<stdio.h>
 
int main() 
{
   int arr[20], i, j, k, size;
 
   printf("nEnter array size : ");
   scanf("%d", &size);
 
   printf("nAccept numbers : ");
   for (i = 0; i < size; i++)
      scanf("%d", &arr[i]);
 
   printf("nArray with unique list  : ");
   for (i = 0; i < size; i++) {
      for (j = i + 1; j < size;) {
         if (arr[j] == arr[i]) {
            for (k = j; k < size; k++) {
               arr[k] = arr[k + 1];
            }
            size--;
         } else
            j++;
      }
   }
 
   for (i = 0; i < size; i++) {
      printf("%d ", arr[i]);
   }
 
   return (0);
}

Output :

Enter array size : 5
Accept numbers : 1 2 3 4 3
Array with unique list  : 1 2 3 4 
Subject Name : Computer Science
Exam Name : IIT GATE, UPSC ESE, RRB, SSC, DMRC, NMRC, BSNL, DRDO, ISRO, BARC, NIELIT
Posts Name : Assistant Engineer, Management Trainee, Junior Engineer, Technical Assistant
Computer Science Books

GATE 2023 Total InfoENGG DIPLOMAUGC NET Total Info
IES 2023 Total InfoPSUs 2022 Total InfoCSIR UGC NET Total Info
JAM 2023 Total InfoM TECH 2023 Total InfoRAILWAY 2022 Total Info

Related Posts

  • Insert Element in An Array : C ProgramComputer Science » C Program » Insert Element in An Array Program : [php]#include<stdio.h> int main() { int arr[30], element, num, i, location; printf("nEnter no of elements : "); scanf("%d", &num); for (i = 0; i < num; i++) { scanf("%d", &arr[i]); } printf("nEnter the element to be inserted : "); scanf("%d", &element); printf("nEnter the location : "); scanf("%d", &location); //Create space at the specified location for (i = num; i >= location; i--) { arr[i] = arr[i - 1]; } num++; arr[location - 1] = element; //Print out the result of insertion for (i = 0; i < num; i++) printf("n %d", arr[i]); return (0); }[/php] Output : [php]Enter no of elements : 5 10 20 30 40 50 Enter the element to be inserted : 60 Enter the location : 3 10 20 60 30 40 50[/php]
    Tags: program, array, computer, science, output, programs
  • Reverse a Given Number : C ProgramComputer Science » C Program » Reverse a Given Number  Program : [php]#include<stdio.h> int main() { int num, rem, rev = 0; printf("nEnter any number to be reversed : "); scanf("%d", &num); while (num >= 1) { rem = num % 10; rev = rev * 10 + rem; num = num / 10; } printf("nReversed Number : %d", rev); return (0); }[/php] Output : [php]Enter any number to be reversed : 123 Reversed Number : 321[/php]
    Tags: program, computer, science, output, programs
  • Even Number Pyramid : C ProgramComputer Science » C Program » Even Number Pyramid Program : [php]#include&lt;stdio.h&gt; int main() { int i, j, num = 2; for (i = 0; i &lt; 4; i++) { num = 2; for (j = 0; j &lt;= i; j++) { printf(&quot;%dt&quot;, num); num = num + 2; } printf(&quot;n&quot;); } return (0); }[/php] Output : [php]2 2 4 2 4 6 2 4 6 8 [/php]
    Tags: program, computer, science, output, programs
  • Searching Element in an Array : C ProgramComputer Science » C Program » Searching Element in an Array Program : [php]#include<stdio.h> int main() { int a[30], element, num, i; printf("nEnter no of elements : "); scanf("%d", &num); printf("nEnter the values : "); for (i = 0; i < num; i++) { scanf("%d", &a[i]); } //Read the element to be searched printf("nEnter the element to be searched : "); scanf("%d", &element); //Search starts from the zeroth location i = 0; while (i < num && element != a[i]) { i++; } //If i < num then Match found if (i < num) { printf("nNumber found at the location : %d", i + 1); } else { printf("nNumber not found."); } return (0); }[/php] Output 1: [php]Enter no of elements : 5 Enter the values : 10 20 30 40 50 Enter the element to be searched : 30 Number found at the location : 3[/php] Output 1: [php]Enter no of elements : 5 Enter the values : 10 20 30 40 50 Enter the element to be searched : 60 Number not found.[/php]
    Tags: program, array, output, computer, science, programs
  • Inverted Pyramid : C ProgramComputer Science » C Program » Inverted Pyramid  Program : [php]#include<stdio.h> int main() { int i, j; char ch = '*'; for (i = 4; i >= 0; i--) { printf("n"); for (j = 0; j < i; j++) printf("%c", ch); } return(0); }[/php] Output : [php]**** *** ** *[/php]
    Tags: program, computer, science, output, programs

LEAVE A REPLY

Please enter your comment!
Please enter your name here