Help little Li solve the problem C + + consolidates the number of digits in each location

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.