Skip to content

Latest commit

 

History

History
34 lines (29 loc) · 366 Bytes

82.md

File metadata and controls

34 lines (29 loc) · 366 Bytes

题目:八进制转换为十进制。 法一:

#include <stdio.h>

int main()
{
	int n;
	scanf("%o", &n);
	printf("%d", n);
	return 0;
}

法二:

#include <stdio.h>
#include <string.h>

int main()
{
	char s[50];
	scanf("%s", s);
	int n = 0;
	for (int i = 0; i < strlen(s); ++i)
	{
		n = n * 8 + s[i] - '0';
	}

	printf("%d", n);

	return 0;
}