Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- using namespace std;
- int main()
- {
- int n;
- cout<<"Enter the size of array = ";
- cin>>n;
- int x[n];
- for(int i=0;i<n;i++){
- cin>>x[i];
- }
- cout<<"Binary Number = ";
- for(int i=0;i<n;i++){
- cout<<x[i];
- }
- cout<<endl;
- int sum = 0;
- cout<<"Sum of the Binary Number to Decimal Number = ";
- for(int i=0;i<n;i++){
- sum =sum + x[i] * pow(2,n-1-i);
- }
- cout<<sum;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement