1-9, divided into three digits, the ratio is

Source: Internet
Author: User

 

C:

# Include <stdio. h>
Bool check (int A []); // puts the number of nine into an array, and checks whether there are the same number through double loop.
Int main (void)
{
Int A [9], I, j, flag = 1;
Int x, y, z;

For (I = 123; I <329; I ++) // the minimum value of X is 123, and the maximum value cannot be 329.
{
X = I;
Y = 2 * I;
Z = 3 * I;

A [0] = x/0/100;
A [1] = (X/10) % 10;
A [2] = x % 10;

A [3] = y/100;
A [4] = (y/10) % 10;
A [5] = Y % 10;

A [6] = z/100;
A [7] = (z/10) % 10;
A [8] = z % 10;

For (j = 0; j <9; j ++)
{
If (A [J] = 0)
Flag = 0;
} // Prevent the second digit from being 0 (when the third digit is 0, there must be repeated digits if the third digit is doubled)

If (flag = 0)
{
Flag = 1;
Continue;
} // When the second number is 0, continue to the next number.

If (check (A) = true)
{
Int I;
For (I = 0; I <9; I ++)
Printf ("% d", a [I]);

Printf ("\ n ");

}

}


}

Bool check (int A [])
{
Int I, J;
For (I = 0; I <9; I ++)
For (j = I + 1; j <= 9; j ++)
{
If (A [I] = A [J])
Return false;

}

Return true;
}

 

 

C ++:

# Include <iostream>
Using namespace STD;
Int main ()
{
Int I, x, y, z;
Int d [9] = {1, 2, 3, 4, 5, 6, 7, 8, 9 };
Do {
X = d [0] * 100 + d [1] * 10 + d [2];
Y = d [3] * 100 + d [4] * 10 + d [5];
Z = d [6] * 100 + d [7] * 10 + d [8];
If (y = x * 2 & Z = x * 3)
Cout <x <Y <z <Endl;
} While (next_permutation (D, D + 9 ));
Return 0;
}

Next_permutation is an arrangement function, and 9 is the length of the arrangement.

 

1-9, divided into three digits, the ratio is

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.