/*
3.7 编写一个程序,以字符形式输入某进制的数字,将其转换为十进制数值并显示出
来。
*/
#include <iostream>
using namespace std;
void main()
{
char a[20] = { 0 };
int i = 0;
int num = 0;
char b = 0;
int jinzhi = 0;
cout << "输入进制:"<<endl;
cin >> jinzhi;
cout << "输入数字: " << endl;
cin>>a;
while (a[i] != '\0')
{
if ('0' <= a[i] && a[i] <= '9')
{
num = num*jinzhi + a[i] - '0';
}
else
{
num = num*jinzhi + a[i] - 55;
}
i++;
}
cout << "转化为十进制数字:" << num<<endl;
system("pause");
}
3.7 编写一个程序,以字符形式输入某进制的数字,将其转换为十进制数值并显示出
来。
*/
#include <iostream>
using namespace std;
void main()
{
char a[20] = { 0 };
int i = 0;
int num = 0;
char b = 0;
int jinzhi = 0;
cout << "输入进制:"<<endl;
cin >> jinzhi;
cout << "输入数字: " << endl;
cin>>a;
while (a[i] != '\0')
{
if ('0' <= a[i] && a[i] <= '9')
{
num = num*jinzhi + a[i] - '0';
}
else
{
num = num*jinzhi + a[i] - 55;
}
i++;
}
cout << "转化为十进制数字:" << num<<endl;
system("pause");
}