#include<stdio.h>

#include<stdio.h>
#include<conio.h>
#include<math.h>

void mergeSort(int arr[],int low,int mid,int high);
void partition(int arr[],int low,int high);
int decimal_binary(int);

int main()
{
   int count=0,k,d[10],c[10],b[10][10],a[10],i,sum=0,n,no,j;
   printf("Enter the number of binary numbers");
   scanf("%d",&no);
   printf("Enter the binary number");
   for(i=0;i<no;i++)
   scanf("%d",&a[i]);
   for(i=0;i<no;i++)
   {
   n=a[i];
   for(j=0;j<4;j++)
   {
   b[i][j]=n%10;
   n=n/10;
   }
   }
   for(i=0;i<no;i++)
   {
   for(j=0;j<4;j++)
   {  
   if(b[i][j]==1)
   sum=sum+pow(2,j);
   }
   c[i]=sum;
   sum=0;
   }
   for(i=0;i<no;i++)
   printf("The value is %d\n",c[i]);
   printf("The multiples of 3 are:\n");
   for(j=0;j<no;j++)
   {
   n=c[j];
   if((n%3)==0){
   printf("%d\t",c[j]);
    d[k++]=c[j];

}   } 
    printf("\ncount = %d",k);
    partition(d,0,k);
    printf("\n\nAfter sorting values are:\n");
    for(i=0;i<k;i++)
    printf("%d\t%d\n",d[i],decimal_binary(d[i]));       
    printf("\n");
//  for(i=0;i<k;k++){
//  n=decimal_binary(d[i]);
//  printf("%d",n);}

   getch();

}



void partition(int arr[],int low,int high){

    int mid;

    if(low<high){
         mid=(low+high)/2;
         partition(arr,low,mid);
         partition(arr,mid+1,high);
         mergeSort(arr,low,mid,high);
    }
}

void mergeSort(int arr[],int low,int mid,int high){

    int i,m,k,l,temp[50];

    l=low;
    i=low;
    m=mid+1;

    while((l<=mid)&&(m<=high)){

         if(arr[l]<=arr[m])
         {
             temp[i]=arr[l];
             l++;
         }
         else
         {
             temp[i]=arr[m];
             m++;
         }
         i++;
    }

    if(l>mid){
         for(k=m;k<=high;k++)
         {
             temp[i]=arr[k];
             i++;
         }
    }
    else
    {
         for(k=l;k<=mid;k++)
         {
             temp[i]=arr[k];
             i++;
         }
    }
    for(k=low;k<=high;k++){
    //  printf("%d\t",temp[k]);
         arr[k]=temp[k];
    }
}


int decimal_binary(int n)  /* Function to convert decimal to binary.*/
{
    int rem, i=1, binary=0;
    while (n!=0)
    {
        rem=n%2;
        n/=2;
        binary+=rem*i;
        i*=10;
    }
    return binary;
}

Are you asking a question?

I have done a program to convert binary to decimal. You can add the code to sort the number in the given code.

#include<iostream.h>
#include<conio.h>
#include<math.h>
void main()
  {
  int a[10],i,no,sum=0,rem,j,k=0;
  clrscr();
  cout<<"Enter Binary No:";
  cin>>no;
  i=0;
  while(no>0)
  {
  a[i]=no%10;
  no=no/10;
  i++;
  }
  for(j=0;j<i;j++)
  {
      sum=sum+a[j]*pow(2,k);
      k++;
  }
  cout<<"Decimal NO:"<<sum;
  getch();
  }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.