Lydia learn number conversion concept in C. Her teacher gave a homework to convert the number from decimal to binary. Help her to convert the number from decimal to binary. Input should be from 0 to 127 64 32 16 8 4 2 1 Test Case 1 Input (stdin) 1 Expected Output 0000001 Test Case 2 Input (stdin) 121 Expected Output 1111001
#include <stdio.h>
int main()
{
long long decimal, tempDecimal, binary;
int rem, place = 1;
binary = 0;
scanf("%lld", &decimal);
tempDecimal = decimal;
while(tempDecimal > 0)
{
rem = tempDecimal % 2;
binary = (rem * place) + binary;
tempDecimal /= 2;
place *= 10;
}
printf("%lld", binary);
return 0;
}