💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
# C 程序:将八进制数转换为十进制数 > 原文: [https://beginnersbook.com/2017/09/c-program-to-convert-octal-number-to-decimal-number/](https://beginnersbook.com/2017/09/c-program-to-convert-octal-number-to-decimal-number/) 该程序将八进制数转换为等效的十进制数。 ## 示例:将八进制转换为十进制的程序 在这个程序中,我们为八进制到十进制转换创建了一个用户定义的函数。程序将八进制数(由用户输入)作为输入,并使用函数将其转换为十进制数。要了解此程序,您应该具有以下 [C 编程](https://beginnersbook.com/2014/01/c-tutorial-for-beginners-with-examples/)主题的知识: 1. [C - 用户自定义函数](https://beginnersbook.com/2014/01/c-functions-examples/) 2. [C `while`循环](https://beginnersbook.com/2014/01/c-while-loop/) ```c #include <stdio.h> #include <math.h> /* This function converts the octal number "octalnum" to the * decimal number and returns it. */ long octalToDecimal(int octalnum) { int decimalnum = 0, temp = 0; while(octalnum != 0) { decimalnum = decimalnum + (octalnum%10) * pow(8,temp); temp++; octalnum = octalnum / 10; } return decimalnum; } int main() { int octalnum; printf("Enter an octal number: "); scanf("%d", &octalnum); printf("Equivalent decimal number is: %ld", octalToDecimal(octalnum)); return 0; } ``` 输出: ```c Enter an octal number: 754 Equivalent decimal number is: 492 ``` 看看这些相关的 C 程序: 1. [C 程序:将八进制转换为二进制](https://beginnersbook.com/2017/09/c-program-to-convert-octal-number-to-binary-number/) 2. [C 程序:将二进制转换为八进制](https://beginnersbook.com/2017/09/c-program-to-convert-binary-to-octal-number-system/) 3. [C 程序:将二进制转换为十进制](https://beginnersbook.com/2015/02/c-program-to-convert-binary-number-to-decimal-number/) 4. [C 程序:将小写字符串转换为大写](https://beginnersbook.com/2015/02/c-program-to-convert-lowercase-string-to-uppercase-string/) 5. [C 程序:将大写字符串转换为小写](https://beginnersbook.com/2015/02/c-program-to-convert-uppercase-string-to-lowercase-string/)