Created
March 25, 2018 05:00
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This would not work for N<99