当前位置:网站首页>【指针】八进制转换为十进制
【指针】八进制转换为十进制
2022-07-06 09:24:00 【|光|】
要求
编一个函数,实现八进制转换为十进制。(用指针实现)
代码
/* * 该函数用来实现将一个八进制数转换为十进制数 * 八进制数以字符串方式存放在形参a所指向的一维字符数组中 * 请将计算得到的十进制数以函数值的方式返回 */
int oct_to_dec(char* a)
{
int d=0;
int i;
int k=strlen(a)-1;
for(i=0;i<20;i++)
{
if(a[i]=='\0')
{
break;
}
else
{
d = d + ((a[i]-48)*pow(8,k));
k--;
}
}
return d;
}
main函数
int main()
{
char a[20];
int n;
gets(a);
n = oct_to_dec(a);
printf("%d",n);
return 0;
}
测试
测试输入
1234
输出
668
边栏推荐
- 内网渗透之内网信息收集(四)
- Record an edu, SQL injection practice
- 网络层—简单的arp断网
- 记一次edu,SQL注入实战
- 攻防世界MISC练习区(gif 掀桌子 ext3 )
- List and data frame of R language experiment III
- "Gold, silver and four" job hopping needs to be cautious. Can an article solve the interview?
- 《统计学》第八版贾俊平第二章课后习题及答案总结
- Web vulnerability - File Inclusion Vulnerability of file operation
- 浅谈漏洞发现思路
猜你喜欢
Harmonyos application development -- address book management system telmanagesys based on listcontainer [phonebook][api v6]
记一次api接口SQL注入实战
《统计学》第八版贾俊平第十章方差分析知识点总结及课后习题答案
Apache APIs IX has the risk of rewriting the x-real-ip header (cve-2022-24112)
captcha-killer验证码识别插件
Hackmyvm target series (6) -videoclub
网络基础详解
HackMyvm靶機系列(3)-visions
《统计学》第八版贾俊平第十一章一元线性回归知识点总结及课后习题答案
xray與burp聯動 挖掘
随机推荐
内网渗透之内网信息收集(二)
Hackmyvm target series (3) -visions
Realize applet payment function with applet cloud development (including source code)
ES全文索引
Database monitoring SQL execution
线程的实现方式总结
The most popular colloquial system explains the base of numbers
Sentinel overall workflow
Solutions to common problems in database development such as MySQL
数据库多表链接的查询方式
{1,2,3,2,5}查重问题
. Net6: develop modern 3D industrial software based on WPF (2)
Web vulnerability - File Inclusion Vulnerability of file operation
Intel oneapi - opening a new era of heterogeneity
移植蜂鸟E203内核至达芬奇pro35T【集创芯来RISC-V杯】(一)
Only 40% of the articles are original? Here comes the modification method
Windows platform mongodb database installation
Bing Dwen Dwen official NFT blind box will be sold for about 626 yuan each; JD home programmer was sentenced for deleting the library and running away; Laravel 9 officially released | Sifu weekly
《统计学》第八版贾俊平第十四章指数知识点总结及课后习题答案
Mysql的事务是什么?什么是脏读,什么是幻读?不可重复读?