Print 1 to the maximum number of n digits:
Here is a very important concept is n-digit, do not know how big N, then you need to use a character to represent a large number
Here is a string to represent the large number, in order to print the time convenient, here need to simulate a character addition operation
In addition, the multiplication of the previously large number of implementations is similar:
http://blog.csdn.net/xietingcandice/article/details/44729323
#include <iostream> #include <string>using namespace Std;int incrument (string& num,int n) {int length = Num.length (); bool Overflag = False;int Nextflag = 0;//< flag carry symbol for (int i = length-1; i>=0;i--) {int nSum = num[i]-' 0 ' + Nextflag;if (i = = length-1) {nsum++;//< last one plus 1}if (NSum <) {Num[i] = nsum+ ' 0 '; break;} if (NSum >=) {if (i = = 0 && Length = = N)//< marked with the highest bit carry, the logo needs to exit the program {overflag = True;break;} Num[i] = nsum-10+ ' 0 '; nextflag = 1;if (i = = 0)//< If the minimum bit carry, then the string needs to be extended, if there is no string using char then in the output there is a certain action {num = ' 1 ' +num;}} return Overflag;} void Printnum (String num) {for (int i = 0; i < num.length (); i++) {cout << num[i];} cout << Endl;} void Printmax (int n) {string num = "0";//< output data if (n = = 0) {return;} while (! Incrument (Num,n)) {printnum (num);}} int main () {Printmax (4); return 0;}
Because the title is only needed to print out the data, it can also be used to directly take advantage of the full array of digital features:
The whole arrangement, basically is a loop plus the process of traversal
#include <iostream> #include <string>using namespace std;void printnum (char* num,int n) {int flag = True;for ( int i = 0; I <n; i++) {if (flag) {if (num[i] = = ' 0 ') {continue;} Else{cout<<num[i];flag = false;}} Else{cout<<num[i];}} if (!flag) {Cout<<endl;}} void printrecursively (char* num, int n, int index) {if (index = = 0) {printnum (num,n); return;} for (int i = 0; i < i++) {num[index-1] = i+ ' 0 '; Printrecursively (num,n,index-1);}} void Printmax (int n) {char *num = new Char[n];if (n = = 0) {return;} for (int i = 0; i < i++) {num[n-1] = i+ ' 0 '; Printrecursively (num,n,n-1);} delete []num;} int main () {Printmax (2); return 0;}
The addition of large numbers, multiplication, the realization of the whole arrangement