Skip to content

Instantly share code, notes, and snippets.

@syedjafer
Created March 25, 2018 05:00
Show Gist options
  • Save syedjafer/2403adf28b4f46f6e1054549ede7569e to your computer and use it in GitHub Desktop.
Save syedjafer/2403adf28b4f46f6e1054549ede7569e to your computer and use it in GitHub Desktop.
A positive integer which comprise of only zeros and ones called Binary-Decimal . To represent the given input in binary decimal , with the minimum count
#include<stdio.h>
int main()
{
int num;
scanf("%d",&num);
int res , val_11 , val_10 ,i;
if(num%11 ==0)
{
res = num/11;
for(i=0;i<res;i++)
{
printf("11");
if(i!=res-1)
{
printf("+");
}
}
}
else if(num%10 == 0)
{
res = num/10;
for(i=0;i<res;i++)
{
printf("10");
if(i!=res-1)
{
printf("+");
}
}
}
else{
val_11 = num/11;
val_10 = num%10;
if(val_10 == val_11)
{
res = num/10;
for(i=0;i<res;i++)
{
printf("10");
printf("+");
}
for(i=0;i<num%10;i++)
{
printf("1");
if(i!=(num%10)-1)
{
printf("+");
}
}
}
else if(val_11 < val_10)
{
res = num/11+num%11;
for(i=0;i<num/11;i++)
{
printf("11");
printf("+");
}
for(i=0;i<num%11;i++)
{
printf("1");
if(i!=(num%11)-1)
{
printf("+");
}
}
}
else
{
res = num/10 + num%10 ;
for(i=0;i<res;i++)
{
printf("10");
printf("+");
}
for(i=0;i<num%10;i++)
{
printf("1");
if(i!=(num%10)-1)
{
printf("+");
}
}
}
}
printf("\nval of count %d",res);
}
@garrykevin-ep
Copy link

This would not work for N<99

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment