forked from zahinekbal/codeWith-hacktoberfest
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdecimal2binaryBasicVoid.c
More file actions
56 lines (43 loc) · 809 Bytes
/
decimal2binaryBasicVoid.c
File metadata and controls
56 lines (43 loc) · 809 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*
# Program for Decimal to Binary Conversion
Given a decimal number as input, we need to write a program to convert the given decimal number into equivalent binary number.
Examples:
Input : 7
Output : 111
Input : 10
Output : 1010
Input: 33
Output: 100001
*/
#include <stdio.h>
void dec2bin(int num)
{
int str[32];
if (num == 0)
{
printf("0\n");
return;
}
int i = 0;
while (num > 0)
{
str[i] = num % 2;
num = num / 2;
++i;
}
for (int j = i - 1; j >= 0; --j)
printf("%d", str[j]);
printf("\n");
}
int main()
{
int t;
scanf("%d\n", &t);
while (t--)
{
int num;
scanf("%d", &num);
dec2bin(num);
}
return 0;
}