Learn C
Coading is not typing it is imagination......
Thursday, July 2, 2015
Decimal to binary by function
#include<stdio.h>
void binary(int decimal)
{
int r,bin=0,p=1;
while(decimal!=0)
{
r=decimal%2;
bin=bin+p*r;
p=p*10;
decimal=decimal/2;
}
printf("%d",bin);
}
int main()
{
int a;
scanf("%d",&a);
binary(a);
return 0;
}
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment