-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBIN-DEC.cpp
More file actions
49 lines (38 loc) · 700 Bytes
/
BIN-DEC.cpp
File metadata and controls
49 lines (38 loc) · 700 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
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int n;
cout << "enter a binary number : ";
cin>>n;
int i=1;
float pv=0,ans=0;
while(n!=0){
int d=n%10;
ans=ans+d*pow(2,pv);
n=n/10;
pv++;
}
cout << "Decimal = " << ans;
}
///Function:
#include<iostream>
#include<cmath>
using namespace std;
int bin_to_dec(int n){
int i=1;
float pv=0,ans=0;
while(n!=0){
int d=n%10;
ans=ans+d*pow(2,pv);
n=n/10;
pv++;
}
cout << "Decimal = " << ans;
}
int main()
{
int n; cout << "Enter a binary number : "; cin>>n;
bin_to_dec(n);
}