History of Idiom 76 > diff from v60 to v61
Edit summary for version 61 by programming-idioms.org:
[Elixir] Revert code, fix URLs
[Elixir] Revert code, fix URLs
↷
Version 60
2019-09-28, 16:49:33
Version 61
2019-10-14, 11:55:36
Idiom #76 Binary digits from an integer
Create the string s of integer x written in base 2.
E.g. 13 -> "1101"
Idiom #76 Binary digits from an integer
Create the string s of integer x written in base 2.
E.g. 13 -> "1101"
Extra Keywords
int radixExtra Keywords
int radixCode
#include<stdio.h>
int toBinary(int decimalNo); //convert a integer number in base 10 to binary
int main(void){
int num;
scanf("%d",&num);
int num_converted = toBinary(num);
printf("The number %d converted to binary is %d", num, num_converted);
}
int toBinary(int decimalNo){
//Base case
if(decimalNo < 2)
return decimalNo;
//Recursive case
return toBinary(decimalNo / 2) * 10 + decimalNo % 2;
}