C Online Compiler
Example: C program to convert decimal to binary using array
C
C++
C#
Java
Python
PHP
main.c
STDIN
Run
// C program to convert decimal to binary using array #include <stdio.h> // The main function of the program int main() { // Step-1 Declare variables int num, binary[32], i = 0; // Step-2 Input a decimal number from the user printf("Enter a decimal number: "); scanf("%d", &num); // Step-3 Convert decimal to binary and store in array while(num > 0) { binary[i] = num % 2; num /= 2; i++; } // Step-4 Print the binary number in reverse order printf("Binary representation: "); for(int j = i - 1; j >= 0; j--) { printf("%d", binary[j]); } printf("\n"); return 0; }
25
Output
Clear
ADVERTISEMENTS