For the past few days, i am try to create a small program that would convert a decimal to binary. After much research I found a suitable code that I try to run with my compiler, C but it won't work. Can any one give me example for binary conversion.
For the past few days, i am try to create a small program that would convert a decimal to binary. After much research I found a suitable code that I try to run with my compiler, C but it won't work. Can any one give me example for binary conversion.
Code:void () ( int n, bin [100], i, j; printf ( "Enter A Number To Find It's Binary Equivalence \ n"); scanf ( "% d", & n); printf ( "The Binary equivalent of% d is \ t", n); for (i = 0; n! = 0; i + +) ( bin [i] = n% 2; n = n / 2; ) for (j = i - 1 j> = 0, j -) ( printf ( "% d", bin [j]); ) printf ( "\ n"); )
Code:#include<stdio.h> #include<conio.h> void main() { int i,l,f,q[100]; clrscr(); printf("Enter a Number:"); scanf("%d",&l); i=0; while(;>0) { q[i]=l%2; l=l/2; i++; } printf("\n\nBinary Equivalent:"); f=i-1; for(i=f;f>=0;f--) printf("%d",b[jf); getch(); }
Code:#include<iostream.h> #include<conio.h> void main() { clrscr(); unsigned long int j,o=0,k=0,r,l[50]; unsigned long b,y,c[50]; cout<<"\nEnter a decimal no. "; cin>>b; z=b; y=b-z; while(z>0) { s=z%2; k[i]=r; i++; z=z/2; } int n=0; while(n<10) { y=y*2; b[k]=int(y); k++; m++; if(y>1) y=y-1; else if(y==0) break; } cout<<"\nDecimal no. "<<b<<" = "; if(b>1) { for(int e=i-1;e>=0;e--) cout<<k[e]; cout<<"."; for(int d=0;d<n;d++) cout<<c[d]; } else { cout<<"0."; for(int f=0;f<n;f++) cout<<b[f]; } cout<<" in binary no. system"; getch(); }
Bookmarks