-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path05.2 (C++) Number Conversions by using switch statement.cpp
More file actions
72 lines (63 loc) · 2.29 KB
/
05.2 (C++) Number Conversions by using switch statement.cpp
File metadata and controls
72 lines (63 loc) · 2.29 KB
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
/// Number Conversions by using switch statement
#include<iostream>
#include<stdio.h>
using namespace std;
int main()
{
int choice, num;
cout<<" ----- Number Conversions ----- \n";
cout<<" Press 1: Decimal to Octal \n";
cout<<" Press 2: Decimal to Hexa-decimal \n";
cout<<" Press 3: Hexa-decimal to Decimal \n";
cout<<" Press 4: Octal to Decimal \n";
cout<<" Press 5: Octal to Hexa-decimal \n";
cout<<" Enter your choice: ";
cin>>choice;
cout<<endl;
switch(choice)
{
case 1:
printf(" Enter the decimal number: ");
scanf("%d", &num);
printf(" Octal number is: %o", num);
break;
case 2:
printf(" Enter the decimal number: ");
scanf("%d", &num);
printf(" Hexa-decimal number is: %x", num);
break;
case 3:
printf(" Enter the hexa-decimal number: ");
scanf("%x", &num);
printf(" Decimal number is: %d", num);
break;
case 4:
printf(" Enter the octal number: ");
scanf("%o", &num);
printf(" Decimal number is: %d", num);
break;
case 5:
printf(" Enter the octal number: ");
scanf("%o", &num);
printf(" Hexa-decimal number is: %x", num);
break;
default:
printf(" Not a number");
break;
}
cout<<endl;
return 0;
}
/* ===== Output / Result:
Input:_______________________________
----- Number Conversions -----
Press 1: Decimal to Octal
Press 2: Decimal to Hexa-decimal
Press 3: Hexa-decimal to Decimal
Press 4: Octal to Decimal
Press 5: Octal to Hexa-decimal
Enter your choose: 1
Enter the decimal number: 25
Output:
Octal number is: 31
*/