当前位置:首页> 搜索优化 > html <%编程积累——html <%实现html ./制与html //制之间的互相转换

html <%编程积累——html <%实现html ./制与html //制之间的互相转换

2022-08-13 21:55:43 来源: 网络   编辑: 佚名   浏览(264)人   
0

html <%编程积累——html <%实现html ./制与html //制之间的互相转换    

html ./制与html //制之间的转换

html ./制转换html //

html ./制对2整除,得到的余数的倒序即为转换而成的html //

html <%实现html ./制转换html //

 主函数main.cpp为:

#html --<iostream>

#html --<fstream>

#html --<string>

#html --<vector>

#html --<cmath>

using namespace std;

int main()

{

int N;

cout << "Please enter the number: ";

cin >> N;

cout << endl;

//html ./制转html //制的声明和调用

void convert_10_to_2(int num);

convert_10_to_2(N);

}

html ./制转换为html //制函数为:

#html --<iostream>

#html --<fstream>

#html --<string>

#html --<vector>

#html --<cmath>

using namespace std;

void convert_10_to_2(int num)

{

vector<int> ivec;

int Num = num; //存储原数据

//对原数据循环求除以2的余数,并存储在vector对象中

while (num != 0)

{

ivec.push_back(num % 2);

num = num / 2;

}

//对求得的余数倒序排序并存储在vector中,求得html //

vector<int>::size_type sz = ivec.size();

vector<int> ivec2;

for (vector<int>::size_type index = 0; index != sz; ++index)

ivec2.push_back(ivec[sz - 1 - index]);

//输出html ./制转换为html //制的数

cout <<Num << "html ./制转html //制后为:";

for (auto item : ivec2)

cout << item;

cout << endl<<endl;

}

html //制转换html ./

html //制从右往左从零次幂开始乘以html //制数并求和

html <%实现html //制转换html ./

html <%主函数为:

#html --<iostream>

#html --<fstream>

#html --<string>

#html --<vector>

#html --<cmath>

using namespace std;

int main()

{

double convert_2_to_10();

convert_2_to_10();

return 0;

}

html //制转html ./制函数为:

#html --<iostream>

#html --<fstream>

#html --<string>

#html --<vector>

using namespace std;

double convert_2_to_10()

{

//输入html //制数并存储在vector变量ivec2

cout << "Please enter the ErJInZhi numbers: " << endl;

int n;

vector<int> ivec2;

while (cin >> n)

{

ivec2.push_back(n);

}

//html //制转html ./制计算

double sum = 0, times;

vector<int>::size_type sz = ivec2.size();

for (vector<int>::size_type index = 0; index != sz; ++index)

{

times = pow(2, sz - 1 - index);

sum += ivec2[index] * times;

}

//输出转化后的结果

cout << "2进制——";

for (vector<int>::size_type index = 0; index != sz; ++index)

cout << ivec2[index];

cout << "10进制为:";

cout << sum << endl;

return 0;

 

【版权与免责声明】如发现内容存在版权问题,烦请提供相关信息发邮件至 1439028666@qq.com ,我们将及时沟通进行删除处理。 本站内容除了 98link( http://www.98link.com/ )特别标记的原创外,其它均为网友转载内容,涉及言论、版权与本站无关。