Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - Beginners C, would like to ask the master to explain the specific meaning of each step of this procedure, thank you.
Beginners C, would like to ask the master to explain the specific meaning of each step of this procedure, thank you.
# include & ltstdio.h & gt// Define header files.

# defineteTRUE 1/defines the constant true as1.

#define FALSE 0 // defines the constant FALSE as 0.

Typedef int Bool// defines the synonym Bool for int. This sentence and the above two sentences forged a Boolean type.

Main()// main function

{

bool digit _ seen[ 10]= { 0 }; //Define a Bool (integer) array named digit_seen, and define each array element as 0 (FALSE).

Int number; //Define an int (integer) variable named digit.

long int n; //define a long integer variable named n.

Printf ("Enter a number:"); //Print (output) "Enter a number on the screen" (excluding quotation marks).

scanf("%ld ",& ampn); //enter a long integer variable and pass it to n.

while(n & gt; 0) {// The loop starts with n >; 0, the loop is executed.

digit = n % 10; //Assign the remainder of n divided by 10 to the digit variable.

If(digit_seen[digit]) // If the digit element of the digit_seen array is not 0 (TRUE)

Break; //and then exit this loop. Combined with the following, if there are two duplicates in n, exit the loop, because n >; at this time; 0, so it provides conditions for the later judgment.

digit _ seen[digit]= TRUE; //If the loop does not exit, the program will run to this sentence. Function: Record that the first digit of the digit_seen array is TRUE, indicating that one digit in n has been used.

n/= 10; //This sentence has the same effect as n=n/ 10, that is, the integer part of n minus 10 times is assigned to n (integer divided by integer or integer).

}//Judge at the beginning of the loop. If n/ 10 is already 0, the loop ends. At this time, n=0 makes conditions for the later judgment.

If (n & gt0) // If n>0, that is, the situation of quitting the loop halfway, it means that there are duplicates in n..

Printf ("Duplicate Numbers \ n \ n"); //output "repeat number" and two line breaks (representing "repeat number")

Else // There is only one possibility of Else here, that is, n=0 means that the loop ends normally, and there is no duplicate number in n..

Printf ("No duplicate numbers \ n \ n"); //Output "No Duplicate Numbers" and two line breaks.

Returns 0; //The program ends normally

}

/* Summary, this program judges whether all digits of a number are repeated, such as 12457 1 repeated, 123456 not repeated */