C program to convert a decimal number into a binary number

Decimal System: A number system with base 10 i.e, numbers from 0-9 are used to represent a decimal number system.

Binary System: A number system with base 2 i.e, only binary numbers 0 and 1 are used to represent a binary number system.

C program to convert a decimal number into a binary number

#include <stdio.h>
#include<stdlib.h>  
 
void main()
{  
int arr[20];
int num,i;    
 
printf("Enter the number: ");    
scanf("%d",&num);  
int n= num;
 
for(i=0;num>0;i++)    
{    
arr[i] = num%2;    
num = num/2;    
}   
 
printf("Binary Value of %d is: ",n);
for(i=i-1; i>=0; i--)    
printf("%d", arr[i]);    
}

Output

Enter the number: 15
Binary value of 15 is: 1111
Please follow and like us:
Content Protection by DMCA.com