Advertisement
Guest User

Untitled

a guest
Apr 2nd, 2020
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.49 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. int n;
  8. cout<<"Enter the size of array = ";
  9. cin>>n;
  10. int x[n];
  11. for(int i=0;i<n;i++){
  12. cin>>x[i];
  13. }
  14. cout<<"Binary Number = ";
  15. for(int i=0;i<n;i++){
  16. cout<<x[i];
  17. }
  18. cout<<endl;
  19. int sum = 0;
  20. cout<<"Sum of the Binary Number to Decimal Number = ";
  21. for(int i=0;i<n;i++){
  22. sum =sum + x[i] * pow(2,n-1-i);
  23. }
  24. cout<<sum;
  25. return 0;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement