No older revisions available
No older revisions available
코드 ¶
~cpp
#include <iostream>
using namespace std;
const int LEN = 50;
bool input(int & num, int & base);
void parse_base(const int num, const int base);
void show_num(const int * parse_num, const int length);
int main()
{
int num, base;
bool isEnd = false;
while (isEnd == false)
{
isEnd = input(num, base);
parse_base(num, base);
}
return 0;
}
bool input(int & num, int & base)
{
cout << "10진수 = ";
cin >> num;
cout << "진법 = ";
cin >> base;
if (num == 0)
return false;
return true;
}
void parse_base(const int num, const int base)
{
int parse_num[LEN];
int length = 0;
int temp = num;
do
{
parse_num[length++] = temp % base;
temp /= base;
}while (temp != 0);
show_num(parse_num, length);
}
void show_num(const int * parse_num, const int length)
{
cout << "결과 = ";
for (int i = length-1; i >= 0; i--)
cout << parse_num[i] << " ";
cout << endl;
}