#include <stdio.h>

int main() {
    int a;
    int b[10];
    int i;
    
    scanf("%d",&a);
    for(i=0;a>0;i++){
        b[i]=a%2;
        a=a/2;
    }
    for(int j=i-1;j>=0;j--){
        printf("%d",b[j]);
    }
}

---------------------------------------------------------------------------

#include<stdio.h>    
#include<stdlib.h>  
int main(){  
int a[10],n,i;  //n=7  
printf("Enter the number to convert: ");    
scanf("%d",&n);    
for(i=0;n>0;i++)    
{    
a[i]=n%2;      // 7%2=1(reminder after division)  : 3%2=1 : 1%2=1  >> 111 answer
n=n/2;         // 7/2=3             --> above     : 3/2=1 : 1/2=0 termination
}    
printf("\nBinary of Given Number is=");    
for(i=i-1;i>=0;i--)    // reverse the binary 
{    
printf("%d",a[i]);    
}    
return 0;  
}  


Embed on website

To embed this program on your website, copy the following code and paste it into your website's HTML: