c - arranging the numbers with duplicate entries deleted -


#include<stdio.h> int main(){ int a[9],i,j,r,t,min,c=0; for(r=0;r<9;r++)     scanf("%d",&a[r]);  (j=0;j<9;j++) {     min=a[j];     for(i=j;i<9;i++) {         if(a[i] <  min ) {             c=i;             min=a[i];         }     } t=a[j]; a[j]=min; a[c]=t; }  for(r=0;r<9;r++)     printf("%d",a[r]); } 

this code have arrange numbers entered byt user in ascending order. if input 1 2 3 2 4 1 5 6 3 output 1 1 2 2 3 3 4 5 6 want output 1 2 3 4 5 6 i.e. duplicate entries deleted.please me.

if range of numbers given can using boolean array store 1 corresponding index of element.

#include <stdio.h> #include <stdbool.h> #define num_range 10  int main(){     int num;     bool freq[num_range + 1] = {0};     for(int r = 0; r < 9; r++){          scanf("%d",&num);          freq[num] = 1;     }      (int = 0; < num_range + 1; i++)          if(freq[i])              printf("%d ", i);  } 

Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -

php - $params->set Array between square bracket -