teddy8 Full Stack Software Engineer

CodeUp - 기초100제(1034)

2019-06-19
teddy8

문제

URL : https://codeup.kr/problemsetsol.php?psid=23


소스코드

// 8진수 입력받아 10진수로 출력
#include <iostream>

using namespace std;

int octToDec(int n);

int main()
{
	int n;
	cin >> n;
	cout << octToDec(n);
	return 0;
}

int octToDec(int n)
{
	int result = 0;
	char cTemp[256];
	_itoa(n, cTemp, 10);

	for (int i = (strlen(cTemp) - 1); i >= 0; i--)
		result += (cTemp[(i - 2) * -1] - 48) * pow(8, i);

	return result;
}


Comments

Content