Friday, March 16, 2012

Duplicate Elimination

Read in 20 numbers, each of which is between 10 and 100, inclusive.Then print it only if it's not duplicate of a number already read.
/*
   title: duplicateElimination
   author: aeriqusyairi
   date: Jan26 2012
*/
#include<stdio.h>
#define SIZE 20

int main(){
   int array[ SIZE ] = { 0 }; 
   int i, j, k = 0, h, number;
   
   printf("Input 20 number between 10 and 100 (inclusive)...\n");
   for(i = 0, h = 0; i < SIZE; i++, k = 0, h++){
      scanf("%d", &number);
      
      for(j = 0; j < SIZE; j++){
         if(number == array[ j ])
            k = 1;         
      } 
      
      if(k == 0){
         printf("You entered an exclusive number %d\n", number );
         array[ h ] = number;     
      }
   }    
   
   system("pause");
   return 0;
}

No comments:

Post a Comment