View Single Post
Old 30-09-2007, 06:47 AM   #262 (permalink)
Gigacore
Dreamweaver
 
Gigacore's Avatar
 
Join Date: Aug 2006
Location: Bangalore
Posts: 3,904
Default Re: Post ur C/C++ Programs Here

[B] A C Program to convert decimal number to its Binary Number Equivalent

Code:
#include <stdio.h>
#include<conio.h>
void main()
{
	auto	int	dec, bin;
	int	dec_to_bin (int);
	printf("Enter a decimal number \n");
	scanf("%d", &dec);
	bin = dec_to_bin (dec);
	printf("The decimal number is = %d \n", dec);
	printf("The binary number is = %d \n", bin);
}
/*	Funtion to find the binary equivalent	*/
int	dec_to_bin (int d)
{
	auto	int	b,r,k;
		b=0;
		k=0;
		while(d>0)
		{
			r = d % 2;
			d = d / 2;
			b = b + r * k;
			k = k * 10;
		}
		return (b);
getch();
}
__________________
Today's noobs are tomorrow's geeks. Don't make fun of them.. encourage them. - Gigacore

Follow me on twitter.com/gigacore
Gigacore is offline