Professional Documents
Culture Documents
com/c-programs/)
Table of Content
C Program to Convert Decimal number into Binary Number
C Program to Convert Decimal number to Octal Number
(http://www.c4learn.com/c-programs/program-for-decimal-number-to-octal.html)
C Program to Convert Decimal Number to Hexadecimal Number
(http://www.c4learn.com/c-programs/program-for-decimal-to-hexadecimal.html)
C Program to Convert Binary to Decimal number
(http://www.c4learn.com/c-programs/program-to-convert-binary-to-decimal.html)
C Program to Convert Decimal to Binary using Bitwise AND operator
(http://www.c4learn.com/c-programs/decimal-to-binary-using-bitwise-and.html)
COMPOSE
#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 :
Explanation of Program :
Always Program execution starts from main function. Inside Main function we are
accepting the decimal number.
Now after accepting the input decimal number we pass the decimal number to function
dec_bin(num) function using following syntax.
dec_bin(num);
// Calling function
Data Type
Initial Value
Use of Variable
rem[50]
long int
Garbage
long int
length
long int
[box]Step 3 : Increase the length of the array by 1 and also increment the subscript
variable[/box]
After the execution of while loop print the array in reverse order.
Official HP Online
Store
Buy HP Original Toner
Cartridges. Free Same Day
Delivery. Pay COD.
Get in Touch!
Recent Programs
C Program to read the content of file using fgets (http://www.c4learn.com/c-programs/readcontent-file-using-fgets.html)
C Program to perform arithmetic operations on float
(http://www.c4learn.com/c-programs/perform-arithmetic-operations-on-float.html)