Program to print binary equivalent of a given decimal integer
Below is the program in C Language that will take decimal number as input. It will then call a function that will calculate the binary equivalent of the input decimal number.
#include#include int i = 0; int b[10]; void main() { int dec; int* DecimalToBinary(int n); int *p, j; printf("Enter a decimal integer = "); scanf("%d", &dec); p = DecimalToBinary(dec); printf("Binary of given decimal integer = "); for (j=i; j>=0; j--) printf("%d", p[j]); printf("\n"); getch(); } int* DecimalToBinary(int n) { while (n != 1) { b[i] = n % 2; n = n / 2; i++; } if (n == 1) { b[i] = 1; } else { b[i] = 0; } return b; }
Superb!!!
#include
int main()
{
int n,i,m,j,rem[100],bin[100];
printf(“\n Enter the number to be converted : “);
scanf(“%d”,&n);
i=0;
m=n;
while(n!=0)
{
rem[i]=n%2;
n=n/2;
i++;
}
for(j=0;j {
bin[j]=rem[i-1-j];
}
printf(“\n Binary Equivalent of %d is : “,m);
printf(“\n”);
for(j=0;j printf(“%d”,bin[j]);
printf(“\n\n”);
return 0;
}
nice solution
gud
Very good solution.plz add more programs
Thank you. You can find the entire list here: https://www.learnconline.com/2010/04/c-programming-examples.html