Thursday, March 27, 2014

A program to find the binary equivalent of the decimal number using function


By on 4:36 AM

I have written a program to find out the binary equivalent of the decimal number using function. Last time I had written the same program without using function. To have clear idea have a look for the source code and the output below:
The output of the above program is:

The main source code of the above output is:



#include<stdio.h>
#include<conio.h>
int i,num, base=1,sum=0,rem,a;
int binary_equivalent(int num);
int main()
{
printf("enter the decimal no whose binary equivalent is to be found\n");
scanf("%d",&num);
a= binary_equivalent(num);
printf("the binary equivalent of the above entered decimal no is \n%d",a);
getch();
}
int binary_equivalent(int num)
{
i=num;
while(num!=0)
{
rem=num%2;
sum=sum+rem*base;
base=base*10;
num=num/2;
}
return sum;
}
view raw biary hosted with ❤ by GitHub

About Authors

Aakash and Shreeram are owners of this website. Both are engineering student. Aakash is studying computer engineering and has passion with blogs and love to play with it while Shreeram is studying civil engineering and has dream of implementing technology in practical life.

0 comments :

Post a Comment