-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoctal.cpp
More file actions
60 lines (60 loc) · 692 Bytes
/
octal.cpp
File metadata and controls
60 lines (60 loc) · 692 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
57
58
59
60
#include<iostream>
#include<cmath>
using namespace std;
int otd()
{
int n;
cin>>n;
int r,i=0,sum=0;
while(n>0)
{
r=n%10;
sum=sum + (pow(8,i)*r);
n=n/10;
i++;
}
cout<<sum<<endl;
return 0;
}
int dto()
{
int n;
cin>>n;
int count=0,sum=0,temp;
temp=n;
while(n>0)
{
n=n/8;
count++;
}
n=temp;
int rem,quo;
while(n>0)
{
rem=pow(8,count-1);
quo=n/rem;
sum=(sum*10)+quo;
n=n%rem;
count--;
}
cout<<sum<<endl;
return 0;
}
int main()
{ int n;
cout<<"1.Octal To Decimal"<<endl;
cout<<"2.Decimal To Octal"<<endl;
cin>>n;
switch(n)
{
case 1:
otd();
break;
case 2:
dto();
break;
default:
cout<<"Invalid Options!!!"<<endl;
}
return 0;
}