#include <iostream>
#include <string>
#include <cmath>
using namespace std;
void main(void){
setlocale(LC_ALL, "rus");
int i,sum=0,n,r=0;
char date[255];
cout << "Введите двоичное число"<< endl;
cin >> date;
n = strlen(date);
int *arr = new int[n];
for (i = 0; i < n; i++){
arr[i] = (int)date[i] - (int)'0';
}
cout << arr[i] << " ";
cout << " " << endl;
r = r + arr[i]*pow(2, n - i-1);
cout << "Десятичное число равно" << r;
Copyright © 2024 SCHOLAR.TIPS - All rights reserved.
Answers & Comments
Verified answer
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
void main(void){
setlocale(LC_ALL, "rus");
int i,sum=0,n,r=0;
char date[255];
cout << "Введите двоичное число"<< endl;
cin >> date;
n = strlen(date);
int *arr = new int[n];
for (i = 0; i < n; i++){
arr[i] = (int)date[i] - (int)'0';
}
for (i = 0; i < n; i++){
cout << arr[i] << " ";
}
cout << " " << endl;
for (i = 0; i < n; i++){
r = r + arr[i]*pow(2, n - i-1);
}
cout << "Десятичное число равно" << r;
}