Decode School

Decode School - The School for Problem Solvers

Welcome to my blog. Subscribe and get my latest blog post in your inbox.

C Program to covert decimal to binary number

Sample Input 1:

11

Sample Output 1:

1011

Program or Solution

					    
							
#include <stdio.h>
 
int main()
{
    	long decimal_num, remainder, base = 1, binary_num = 0;
 	printf("Enter decimal number:");
    	scanf("%ld", &decimal_num);
 
    	while (decimal_num > 0)
    	{
        	remainder = decimal_num % 2;
        	binary_num = binary_num + remainder * base;
        	decimal_num = decimal_num / 2;
        	base = base * 10;
    	}
    	printf(" Binary Value: %ld\n", binary_num);
    	return 0;
}
					    
					

Program Explanation

yet to be updated