码迷,mamicode.com
首页 > 其他好文 > 详细

例36:N进制转十进制

时间:2017-01-21 23:23:04      阅读:268      评论:0      收藏:0      [点我收藏+]

标签:code   ret   turn   style   strlen   main   amp   相加   for   

直接撸代码,不废话。

代码如下:

 1 #include<stdio.h> 
 2 #include<stdlib.h>
 3 #include<string.h>
 4 void Test(int n,char *p)
 5 {
 6     int nCount = strlen(p),sum = 0;
 7     for(int temp = 1,i = nCount-1;i>=0;i--)
 8     {
 9         sum += temp*(p[i] - 0);//得出其每一位真实值并相加 
10         temp*=n;
11     }
12     printf("%d\n",sum);
13 }
14 int main()
15 {
16     int n;
17     while(~scanf("%d",&n) && n)
18     {
19         char p[30];
20         scanf("%s",p);
21         Test(n,p);
22     }
23     
24     return 0;
25 }

 

例36:N进制转十进制

标签:code   ret   turn   style   strlen   main   amp   相加   for   

原文地址:http://www.cnblogs.com/FWFC/p/6337969.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!