C 练习实例82

C语言教程评论

C 练习实例82

题目:八进制转换为十进制

程序分析:无。文章源自公式库网-https://www.gongshiku.com/html/202112/c-lianxishili82.html

实例

#include<stdio.h>
#include<stdlib.h>
int main()
{
    int n=0,i=0;
    char s[20];
    printf("请输入一个8进制数:\n");
    gets(s);
    while(s[i]!='\0'){
        n=n*8+s[i]-'0';
        i++;
    }
    printf("刚输入的8进制数转化为十进制为\n%d\n",n);

    return 0;
}

以上实例运行输出结果为:文章源自公式库网-https://www.gongshiku.com/html/202112/c-lianxishili82.html

请输入一个8进制数:
16
刚输入的8进制数转化为十进制为
14
文章源自公式库网-https://www.gongshiku.com/html/202112/c-lianxishili82.html文章源自公式库网-https://www.gongshiku.com/html/202112/c-lianxishili82.html
运营不易,
感谢支持!
weinxin
我的微信
我的微信公众号
我的微信公众号扫一扫
weinxin
我的公众号
 最后更新:2021-12-7
公式库网
  • 本文由 公式库网 发表于 2021年12月6日21:14:44
  • 转载请务必保留本文链接:https://www.gongshiku.com/html/202112/c-lianxishili82.html

发表评论