Monday, April 30, 2018

How to convert Decimal to Binary using Array Number System Part 3

#include<stdio.h>
main()
{
    int n,i=0,j,base=2;
    int bin[100];
    scanf("%d",&n);
    while(n!=0)
    {
        bin[i++]=n%base;
        n=n/base;
    }
    for(j=i-1;j>=0;j--){
        printf("%d",bin[j]);
    }
}

Sunday, April 29, 2018

How to convert Decimal to Binary_Most_Basic_(Number_System_Part_1)

#include<stdio.h>
main()
{
    int n,rem,bin=0,k=1;
    printf("Enter a decimal number ");
    scanf("%d",&n);
    while(n!=0)
    {
        rem=n%2;
        bin=bin+rem*k;
        k=k*10;
        n=n/2;

    }
    printf("Binary = %d\n",bin);

}