We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent f8f4676 commit 4499583Copy full SHA for 4499583
convertb.c
@@ -0,0 +1,32 @@
1
+#include <stdio.h>
2
+
3
+void decToBinary(int n) {
4
+ if (n == 0) {
5
+ printf("0");
6
+ return;
7
+ }
8
9
+ int binary[32];
10
+ int i = 0;
11
12
+ while (n > 0) {
13
+ binary[i] = n % 2;
14
+ n = n / 2;
15
+ i++;
16
17
18
+ for (int j = i - 1; j >= 0; j--)
19
+ printf("%d", binary[j]);
20
+}
21
22
+int main() {
23
+ int num;
24
+ printf("Insert first number: ");
25
+ scanf("%d", &num);
26
27
+ printf("The binary number is: ");
28
+ decToBinary(num);
29
+ printf("\n");
30
31
+ return 0;
32
0 commit comments