C Online Compiler
Example: C program to convert decimal to binary without using array
C
C++
C#
Java
Python
PHP
main.c
STDIN
Run
// C program to convert decimal to binary without using array #include <stdio.h> // The main function of the program int main() { // Step-1 Declare variables int num; long long binary = 0; int remainder, place = 1; // Step-2 Input a decimal number from the user printf("Enter a decimal number: "); scanf("%d", &num); // Step-3 Convert decimal to binary manually using loop while(num != 0) { remainder = num % 2; binary += remainder * place; num /= 2; place *= 10; } // Step-4 Output the binary number printf("Binary representation: %lld\n", binary); return 0; }
10
Output
Clear
ADVERTISEMENTS