forked from wbhima/CodeforALL
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNumConversion.cpp
More file actions
43 lines (42 loc) · 767 Bytes
/
Copy pathNumConversion.cpp
File metadata and controls
43 lines (42 loc) · 767 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
#include<iostream>
#include<conio.h>
#include<cmath>
using namespace std;
int main()
{ int ch;
cout<<"1.)To convert Decimal to Binary \n2.)To convert Binary to Decimal";
cout<<"\nEnter your choice: ";
cin>>ch;
switch(ch)
{
case 1: int n;
cout<<"Enter a number in decimal form: ";
cin>>n;
long dig;
while(n!=0)
{
dig=n%2;
n/=2;
cout<<dig;
}
break;
case 2: {
long x;
cout<<"Enter a number in binary form: ";
cin>>x;
int rem,sum=0,i=0;
while(x!=0)
{
rem=x%10;
x=x/10;
sum+=rem*pow(2,i);
i++;
}
cout<<"\nDecimal form of the given number is: "<<sum;
break;
}
default: cout<<"\nWrong choice entered!!";
}
getch();
return 0;
}