Now there is a number a= 12345;
Want to get this number without a number use Division + modulo method to get
Principle: Except (/) to obtain the remainder of the Shangmo (%)
In this way, one of the required numbers is divided by the number of bits (a Chichong) and then divided into units.
Formula: A/(number of digits to be obtained)%10
Such as:
Million bit: 12345/10000%10 = 1;
thousand: 12345/1000%10 = 12%10 = (1...2) = 2;
Hundred: 12345/100%10 = 123%10= (12.....3) = 3;
10 bits: 12345/10%10 = 1234%10= (123.....4) = 4;
Digit: 12345/1%10 = 12345%10 = (1234...5) = 5;
1#include <iostream>2 using namespacestd;3 intMain () {4 inti;5 inta,b,c,d;6 7 for(i= -; i<= +; i++){8A = i/1%Ten;9b = i/Ten%Ten;Tenc = i/ -%Ten; One A if((a+b+c) = =5){ -D=i; -cout<<"and for the number of 5 there are:"<<d<<Endl; the } - } - - return 0; +}
View Code
Each number itself modulo a number larger than its own when equal to its own in the binary number is the largest i%i = 0;
Help little Li solve the problem C + + consolidates the number of digits in each location