C Program to convert no. from decimal to binary

Posted: January 19, 2012 in Lab 2
#include<stdio.h>

int main()
{

int dec,i=1,rem,res=0,*ptr;
printf("Enter the Value\n ");
scanf("%d",&dec);
	ptr=&dec;
while(*ptr!=0)
{


res=res+(i * (rem=*ptr%2));
dec=dec/2;
i=i*10;

}
printf("\nThe Binary value is %d\n",res);

}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s