img
Question:
Published on: 3 December, 2024

Write a C program to convert decimal no. to binary.

Answer:

 

#include<stdio.h>
#include<conio.h>
main()
{
	int bin[50],i=0,n,j;
	printf("\n Enter any decimal number");
	scanf("%d",&n);
	while(n>0)
	{
		bin[i]=n%2;
		n=n/2;
		i++;
	}
	for(j=i-1;j>=0;j--)
	{
		printf(" %d ",bin[j]);
	}
	getch();
}

 

Output:

Random questions