Code for Decimal to Binary conversion
For learning c code, students are advised to practice few basic codes, Decimal to Binary conversion is one of them.
In C code practice, this program logic plays a very important role. So I have designed this code as easy as possible for the students. They will be able to understand each and every step very easily.
Before going for this type of program a student should go through basics of loop structure. So that they can easily go through each step with self explanation mode.
For more code click here. For video tutorial on several topics click here.
#include <stdio.h> void dectobin(int); int main() { int bin,dec; printf("Enter the number : "); scanf("%d",&dec); printf("Binary form is : "); dectobin(dec); return 0; } void dectobin(int dec) { int bit; if(dec!=0) { bit=dec%2; dectobin(dec/2); printf("%d",bit); } }