c++ 输出N位m进制所有数字, 例如输入:3 2 输出:000 001 010 011 100 101 110 111

如题所述

第1个回答  2011-06-09
windows平台下的特有函数itoa(222, buf, 2);buf里面就存有222的2进制字符串
标准c++下没有这种函数本回答被提问者采纳
第2个回答  2011-06-09
#include <iostream>
#include <cmath>
using namespace std;

struct Node{
Node *children;
char *data;
};

void getnum(int n, int m);

int main()
{
getnum(4, 2);

return 0;
}

void putNode(Node& root, int m, int n, int &l)
{
if (l >= n)
{
cout<<root.data<<' ';
delete root.data;
return;
}
l += 1;
int i = 0;
root.children = new Node[m];
for (;i < m; i++)
{
int k = l;
root.children[i].data = new char[n + 1];
strcpy(root.children[i].data, root.data);
root.children[i].data[k - 1] = i + '0';
root.children[i].data[k] = '\0';
putNode(root.children[i], m, n, k);
}
delete root.data;
}

void getnum(int n, int m)
{
Node root;
int i = 0;
int j = 0;

root.data = new char[n + 1];
root.data[0] = '\0';
putNode(root, m, n, j);

};追问

看着晕啊

第3个回答  2011-06-11
MOV AH,13H
MOV AL,88H
MOV BH,03H
MOV BL,0EBH
DIV BX
结果 AH 保存商 AL保存余数
相似回答