Decimal to binary conversion
Posted by Spider on 5:45 AM
#include <stdio.h> int main() { int n, c, k; printf("\nEnter an integer in decimal number system ::");
scanf("%d", &n); printf("\n%d in binary number system is ::", n); for (c = 31; c >= 0; c--) { k = n >> c; if (k & 1) printf("1"); else printf("0"); } printf("\n"); return 0; }
/*
Output :
Enter an integer in decimal number system :: 5
5 in binary number system is :: 101
*/
Tags
C Basics