Skip to content

Instantly share code, notes, and snippets.

@jagdish4501
Created May 12, 2021 08:22
Show Gist options
  • Save jagdish4501/986819866fd0450b90118a20a9bc8c57 to your computer and use it in GitHub Desktop.
Save jagdish4501/986819866fd0450b90118a20a9bc8c57 to your computer and use it in GitHub Desktop.
Let us c Q.Write a function to find the binary equivalent of a given decimal integer and display it.
#include <stdio.h>
int fun(int num);
int main()
{
int num;
printf("Enter Number: ");
scanf("%d", &num);
printf("\nDecimal To Binary : %d", fun(num));
}
int fun(int num)
{
int x, res = 0, pos = 1;
while (num != 0)
{
x = num % 2;
res = res + (x * pos);
pos = 10 * pos;
num = num / 2;
}
return res;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment