《c程序设计语言》读书笔记-3.5-按要求进制位数字转字符串
2024-09-03 11:17:51
#include <io.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h> void reverse(char s[])
{
int c,i,j; for(i = 0,j = strlen(s) - 1;i < j;i++,j--)
c = s[i],s[i] = s[j],s[j] = c;
} void itoa(int n,char s[],int b)
{
int i,sign,j; sign = n,i = 0; do
{
j = abs(n % b);
s[i++] = (j <= 9) ? j + '0' : j - 10 + 'a';
}while((n /= b) != 0); if(sign < 0)
s[i++] = '-';
s[i] = '\0';
reverse(s);
} int main()
{
int n,i,b;
char s[50];
n = -165;
b = 16; itoa(n,s,b); for(i = 0;i < strlen(s);i++)
printf("%c ",s[i]); return 0;
}
最新文章
- 基础的jdbc连接数据库操作
- java基本类型的默认值及其取值范围
- jieba中文分词的.NET版本:jieba.NET
- Pyqt 中__init__(self,parent==None) parent理解
- memcache/redis 缓存学习笔记
- CentOS 6.5 无网环境安装R及Rstudio的方法的方法
- Redis PHP通用类
- 11g新特性与12c新特性
- 云服务器 ECS Linux 系统中常见的日志文件介绍
- GridView绑定DataKeyNames以及如何取这些值
- EF CodeFirst系列(2)---CodeFirst的数据库初始化
- codeforces 915E - Physical Education Lessons 动态开点线段树
- javascript websocket 心跳检测机制介绍
- python之字符串拼接:%和format
- angular点击查看更多(简单demo)
- 2012年蓝桥杯省赛A组c++第3题(喝断片的海盗)
- 如何下载网页上的视频和flash的方法
- 如何知道我 的python是32位还是64位的?
- 两招解决异常_Cannot find any information on property &#39;XXX&#39; in a bean of type &#39;XXX&#39;的问题
- @Transational)的方法,注解失效的原因和解决方法