Problem Description
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 1Test Case 1
Input (stdin)1
Expected Output0000001
Test Case 2
Input (stdin)121
Expected Output1111001
Program
#include <stdio.h> int main() { int n,c,k; scanf("%d",&n); for(c=6;c>=0;c--) { k=n>>c; if(k&1) printf("1"); else printf("0"); } return 0; }
No comments:
Post a Comment
Note: only a member of this blog may post a comment.