Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- #include <conio.h>
- long int binary(int a); //chuyen decimal sang binary
- int main(){
- int x; long int bi;
- printf("Convert Decimal to Binary program\n");
- while (1)
- {
- printf(" Enter a positive integer number: ");
- fflush(stdin);
- scanf("%d",&x);
- bi = binary(x);
- printf(" Binary number: : %ld\n",bi);
- printf("Press any key to do another conversion.\n\n");
- getch();
- }
- return(0);
- }
- long int binary(int a){
- long int bi=0,x=1; int b;
- while (a>0){
- b= a%2;
- bi+= b*x;
- x*= 10;
- a/=2;
- }
- return(bi);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement