Program to Convert Decimal number into Binary : Number System :

February 6, 2025 1 Comment » Hits : 782





Program to Convert Decimal number into Binary : Number System : Download


Logic of This Program :

  1. Accept Number from User
  2. As we are dividing number by 2, we have only remainders 0,1 etc
  3. Take an array of remainder i. rem[20];
  4. Let ,Initial elements in rem[] be Zero
  5. In each iteration Store Remainder in the Array & Divide original number by 2
  6. Also Count the number of remainders stored
  7. To Convert into Binary Just Reverse Remainder array

Program :

#include<stdio.h>
#include<conio.h>
#include<math.h>
void dec_bin(long int num)   // Function Definition
{
long int rem[50],i=0,length=0;
while(num>0)
 {
 rem[i]=num%2;
 num=num/2;
 i++;
 length++;
 }
printf("\nBinary number : ");
     for(i=length-1;i>=0;i--)
             printf("%ld",rem[i]);
}
//================================================
void main()
{
long int num;
clrscr();
 printf("Enter the decimal number : ");
 scanf("%ld",&num);
    dec_bin(num);   // Calling function
 getch();
}

Output :

Enter the decimal number : 7 
Octal number : 111

Download Code


Incoming search terms:

  • Latoria Portes

    Great post, I conceive people should acquire a lot from this blog its really user friendly. So much superb info on here .