Tuesday, 10 January 2012

Write a C program to convert Decimal into Binary

#include<stdio.h>
#include<conio.h>

void main()
{
    int i,n,a[8],rem;
    clrscr();
    printf("Enter any decimal number::\n");
    scanf("%d",&n);
    for(i=7;i>=0;i--)
    {
        rem=n%2;
        a[i]=rem;
        n=(int)n/2;
    }
    printf("\nThe binary number is=");
    for(i=0;i<8;i++)
    printf("%d",a[i]);
    getch();
}

1 comment: