Program to Convert Decimal number into Binary : Number System : Download
Logic of This Program :
- Accept Number from User
- As we are dividing number by 2, we have only remainders 0,1 etc
- Take an array of remainder i. rem[20];
- Let ,Initial elements in rem[] be Zero
- In each iteration Store Remainder in the Array & Divide original number by 2
- Also Count the number of remainders stored
- 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
Incoming search terms:
- number system in programming (4)
- c program to convert a decimal number into a binary number (3)
- program in c that converts decimal number to binary number system (2)
- Program to convert decimal number into binary number (2)
- program that converts all number system in c (2)
- ‘c’ program to convert decimal number into binary number (2)