-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
97 lines (97 loc) · 1.88 KB
/
main.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include <stdio.h>
#include <stdlib.h>
int DECtoALL (){
st:{
long int x;
long long int y=1,i=0;
printf("enter the DEC number: \n");
scanf("%ld",&x);
if(x!=0){
printf("HEX : %lX\n",x);
printf("OCT : %lo\n",x);
while(x!=0){
i+=(x%2)*y;
y*=10;
x/=2;
}
printf("BIN : %lld\n",i);
goto st;
}
}
}
int BINtoALL (){
st:{
long long int x,y=1,i=0;
printf("enter the BIN number: \n");
scanf("%lld",&x);
if(x!=0){
while(x!=0)
i+=(x%10)*y,y*=2,x/=10;
printf("DEC : %lld\n",i);
printf("HEX : %llX\n",i);
printf("OCT : %llo\n",i);
goto st;
}
}
}
int HEXtoALL (){
st:{
long long int x,i=0,y=1;
printf("Enter a HEX number\n");
scanf("%llX",&x);
if(x!=0){
printf("DEC : %lld\n",x);
printf("OCT : %llo\n",x);
while(x!=0)
i+=(x%2)*y,y*=10,x/=2;
printf("BIN : %lld\n",i);
goto st;
}
}
}
int OCTtoALL (){
start:{
long int x,y=1,i=0;
printf("Enter a OCT number\n");
scanf("%lo",&x);
if(x!=0){
printf("DEC : %ld\n",x);
printf("HEX : %lX\n",x);
while(x!=0){
i+=(x%2)*y;
y*=10;
x/=2;
}
printf("BIN : %ld\n",i);
goto start;
}
}
}
int main(void) {
start:{
int x;
printf("choose your operation\n");
printf("1_DEC to ALL\n");
printf("2_BIN to ALL\n");
printf("3_HEX to ALL\n");
printf("4_OCT to ALL\n");
scanf("%d",&x);
switch(x){
case 1 :
DECtoALL ();
break;
case 2 :
BINtoALL ();
break;
case 3 :
HEXtoALL ();
break;
case 4 :
OCTtoALL ();
break;
default:
printf("Error !!!\n");
}
goto start;
}
}