Created
May 12, 2021 08:22
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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