Advertisement
Rakibul_Ahasan

Problem-02->BinaryToDecimal(Lab-01/Numerical)

Feb 10th, 2020
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.39 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6.     long long n;
  7.     cin>>n;
  8.  
  9.     long long ar[n];
  10.  
  11.     for(int i=0;i<n;i++){
  12.         cin>>ar[i];
  13.     }
  14.  
  15.     for(int i=n-1,j=0;i>=0;i--,j++){
  16.         ar[i]=ar[j];
  17.     }
  18.  
  19.     ///reverse(&ar[0],&ar[n]);
  20.  
  21.     int sum=0;
  22.     for(int i=n-1,j=0;i>=0;i--,j++){
  23.         sum+=(ar[i]*pow(2,j));
  24.     }
  25.     cout<<sum<<endl;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement