CONVERSION OF DECIMAL TO BINARY USING C PROGRAM









#include<stdio.h>
int main(){
  long int m,no=0,a=1;
  int n,rem;
  printf("Enter any decimal number->");
  scanf("%d",&n);
  m=n;
  while(n!=0){
      rem=n%2;
      no=no+rem*a;
      n=n/2;
     a=a*10;
  }
  printf("The value %ld in binary is->",m);
  printf("%ld",no);
  return 0;
}




Alogrithm:
**






1. Write a c program to convert decimal number to hexadecimal number.
3. Write a c program to convert octal number to decimal number.
4. Write a c program to convert octal number to hexadecimal number.
5. Write a c program to convert hexadecimal number to decimal number.
6. Write a c program to convert hexadecimal number to octal number.
8. Write a c program to convert binary number to hexadecimal number.
9. Write a c program to convert binary number to octal number.
11. Write a c program to convert hexadecimal number to binary number.
12. Write a c program to convert octal number to binary number.
14. Write a c program to convert centigrade to fahrenheit.


6 comments:

xee said...

this code seems to work only for small numbers.
i tried to input 32 but it gives the wrong output. how come?

Anonymous said...

I tried this code but it didn't work with large numbers.

yogesh_madhuri said...

#include
#include
int main()
{
int no,p=0,rem;
long int sum=0;
printf("Enter a number:");
scanf("%d",&no);
while(no!=0)
{
rem=no%2;
sum=sum+rem*pow(10,p);
no=no/2;
p++;
}
printf("The Binary Equivalent is:%ld\n",sum);
return 0;
}

Anonymous said...

change the int to long and this code works for large no

khushi said...

can any one explain me the above program

Anonymous said...

this helped me a lot