c++编写递归函数char *itostr (int n,char *string),该函数将整数n转换为十进制表示的字符串。
#include<iostream>
#include<stdio.h>
using namespace std;
int i=;
char *itostr (int n,char *String)
{
String[i]=(n%)+;
i++;
if(n/==)
return String;
else
itostr(n/,String); } int main()
{
int n;
cout<<"input the number:"<<endl;
cin>>n;
char String[];
itostr(n,String);
cout<<"输出字符串:"<<endl;
for(int j=i-;j>=;j--)
cout<<String[j];
return ;
}
输出样式:

c++编写递归函数char *itostr (int n,char *string),该函数将整数n转换为十进制表示的字符串。的更多相关文章
- unicode下各种类型转换,CString,string,char*,int,char[]
把最近用到的各种unicode下类型转换总结了一下,今后遇到其他的再补充: 1.string转CString string a=”abc”; CString str=CString(a.c_str() ...
- 用c++语言编写函数 int index(char *s,char * t),返回字符串t在字符串s中出现的最左边的位置,如果s中没有与t匹配的子串,则返回-1。类似于索引的功能。
首先,分析一下程序的思路: 1:从s的第i个元素开始,与t中的第1个元素匹配,如果相等,则将s的第i+1元素与t中的第2个元素匹配,以此类推,如果t所有元素都匹配,则返回位置i;否则,执行2; 2: ...
- C++ 中 char 与 int 转换问题
itoa 功 能:把一整数转换为字符串 函 数:char *itoa(int value, char *string, int radix); 解 释:itoa 是英文integer to ar ...
- 基本类型数据转换(int,char,byte)
public class DataUtil { public static void main(String[] args) { int a = 8; int value = charToInt(by ...
- cstring、string、wstring、int、char*、tchar、 int、dword等相互转换代码输出测试
#include <string> #include <tchar.h> // _TCHAR #include <stdlib.h> #include <io ...
- C++ int与char[]的相互转换
C++ int与char[]的相互转换 一.itoa函数与atio函数①把int类型数字转成char类型,可以使用itoa函数. itoa函数原型: char*itoa(int value,char* ...
- 不使用库函数,编写函数int strcmp(char *source, char *dest) 相等返回0,不等返回-1;
答案:一. int strcmp(char *source, char *dest) { /* assert的作用是现计算表达式 expression ,如果其值为假(即为0),那么它先向stder ...
- 不使用库函数,编写函数int strcmp(char *source, char *dest) 相等返回0,不等返回-1【转】
本文转载自:http://www.cppblog.com/mmdengwo/archive/2011/04/14/144253.aspx #include <stdio.h>#includ ...
- 编写函数int count_number_string(char str[])和函数int maxnum_string(char str[])
题目如图: 这里不再赘述 代码: //字符串中统计与查询 //杨鑫 #include <stdio.h> #include <stdlib.h> #include <st ...
随机推荐
- 《OD大数据实战》Spark入门实例
一.环境搭建 1. 编译spark 1.3.0 1)安装apache-maven-3.0.5 2)下载并解压 spark-1.3.0.tgz 3)修改make-distribution.sh VER ...
- cf837E(xjb)
题目链接:http://codeforces.com/problemset/problem/837/E 题意:f(a, 0) = 0 , f(a, b) = 1 + f(a, b - gcd( ...
- 基础篇 - pg_isready
pg_isready 发起一个到指定 PostgreSQL数据库的连接检查. 使用方法: pg_isready [选项]... 选项: -d, --dbname=DBNAME 数据库名 -q, --q ...
- PHP下载远程图片的几种方法总结
1. 使用file_get_contents function dlfile($file_url, $save_to) { $content = file_get_contents($file_url ...
- [题解](排列/逆序对)luogu_P1338末日的传说
首先我们要考虑怎么排能使逆序对数最多:显然是下降序列时,会产生n*(n-1)/2数量的逆序对 那么我们肯定是要尽量把序列的尾端安排成下降序列,前面的尽量不动,中间可能有一段排列自适应到m的逆序对数 然 ...
- CCF201809(Java)
第一题: 问题描述 在一条街上有n个卖菜的商店,按1至n的顺序排成一排,这些商店都卖一种蔬菜. 第一天,每个商店都自己定了一个价格.店主们希望自己的菜价和其他商店的一致,第二天,每一家商店都会根据他自 ...
- Codeforces Round #364 (Div. 2) C
Description Sergei B., the young coach of Pokemons, has found the big house which consists of n flat ...
- FileChannel与ByteBuffer的使用示例
DirectByteBuffer直接内存的使用场景和作用 生命周期长的大对象, 减少java堆GC, 减少内存copy http://www.importnew.com/26334.html publ ...
- 02------css选择器
css的选择器:1.基本选择器 2.高级选择器 基本选择器包含: 1.标签选择器标签选择器可以选中所有的标签元素,比如div,ul,li ,p等等,不管标签藏的多深,都能选中,选中的是所有的,而不是某 ...
- python3+Appium自动化08-数据配置yaml
yaml简介 yaml是一种简洁的非标记语言.yaml以数据为中心,使用空白,缩进,分行组织数据,从而使得表示更加简洁易读 由于实现简单,解析成本低,yaml特别适合在脚本语言中使用.现有的语言实现: ...