Skip to content

Commit 4499583

Browse files
committed
Ho creato l'esercizio di conversione
1 parent f8f4676 commit 4499583

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

convertb.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)