/*Write a C program to convert given decimal into its euivalent binary.
Coded by KoDes4u.blogspot.com*/
#include<stdio.h>
#include<conio.h>
#define MAX 10
void convert(int dec_num,int bin_num[]);
void main()
{
int dec_num,bin_num[MAX];
clrscr();
printf("\nEnter a decimal number:");
scanf("%d",&dec_num);
convert(dec_num,bin_num);
getch();
}
void convert(int dec_num,int bin_num[])
{
int i=0,j;
while(dec_num!=0)
{
bin_num[i]=dec_num%2;
dec_num=dec_num/2;
i++;
}
printf("\nThe Binary equivalent is:");
for(j=i-1;j>=0;j--)
printf("%d",bin_num[j]);
}
No comments:
Post a Comment