-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathdta.c
70 lines (70 loc) · 1.17 KB
/
dta.c
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include<stdio.h>
void binary(int d)
{
int arr[1000],i=0;
while(d>0)
{
int a=d%2;
d=d/2;
arr[i]=a;
i++;
}
for(int j=i-1;j>=0;j--)
printf("%d",arr[j]);
printf("\n");
}
void octal(int d)
{
int arr[1000],i=0;
while(d>0)
{
int a=d%8;
d=d/8;
arr[i]=a;
i++;
}
for(int j=i-1;j>=0;j--)
printf("%d",arr[j]);
printf("\n");
}
void hexa(int d)
{
int arr[1000],i=0;
while(d>0)
{
int a=d%16;
d=d/16;
arr[i]=a;
i++;
}
for(int j=i-1;j>=0;j--)
{
if(arr[j]==10)
printf("A");
else if(arr[j]==11)
printf("B");
else if(arr[j]==12)
printf("C");
else if(arr[j]==13)
printf("D");
else if(arr[j]==14)
printf("E");
else if(arr[j]==15)
printf("F");
else
printf("%d",arr[j]);
}
printf("\n");
}
void main()
{
int d;
printf("Input a number : ");
scanf("%d",&d);
printf("Binary number is : ");
binary(d);
printf("Octal number is : ");
octal(d);
printf("Hexadecimal number is : ");
hexa(d);
}