八进制与十进制之间的转换C语言

八进制转十进制,十进制转八进制

#include<stdio.h>

#include<math.h>

intmain()

{

    int n,now=0,i,remainder;

         scanf("%d",&n);

    for(i=0;;i++)

         {

                   remainder=n%10;

                   now=now+remainder*pow(8,i);

                   if(n/10==0)

                   {

                            printf("%d\n",now);

                            break;

                   }

                   n=n/10;   

         }

         scanf("%d",&n);

         now=0;

         for (i=0;;i++)

         {

                   remainder=n%8;

                   now=now+remainder*pow(10,i);

                   if(n==0)

                   {

                            printf("%d\n",now);

                            break;

                   }

         n=n/8;

         }

         return 0;

}


阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/munan2017/article/details/80316394
个人分类: C语言习题
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭