U E D R , A S I H C RSS

진법바꾸기/문보창

소감

코드

~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;
}

나한테 할말

Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:31:14
Processing time 0.0152 sec