Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - Emergency rescue is written in C language: 1. Write a function to find the larger value of two numbers and call it in the main function. 2. Sort 10 integer (ascending order).
Emergency rescue is written in C language: 1. Write a function to find the larger value of two numbers and call it in the main function. 2. Sort 10 integer (ascending order).
1、

int max(int a,int b)

{

return a & gtb? A: b;

}

2、

# include & ltstdio.h & gt// Link standard header files.

#define N 5 // define the constant n and assign it to 5.

Void main() // main function entry

{//indicates the beginning of the main function.

int i,j; //define integer variables I and J.

Int grade[N], temp// defines an n-dimensional (n = 5, that is, five-dimensional) plastic array and a plastic variable temp.

Printf ("Enter 5 digits \ n"); //Explicitly "Enter 5 Numbers" on the screen and wrap the line.

for(I = 0; I & ltn;; I++) // Start the for loop, starting from I = 0, adding 1 each time until I = 4, and * * * needs to loop for 5 times.

{//Cycle body start

Scanf("%d ",& grade [i]); //Get the integer values input by the user in turn and store them in the array grade.

}//End of loop

for(I = 0; I & ltn;; I++) // Start the outer loop of for, starting with I = 0 and adding 1 at a time until i=4.

{//The external circulation body begins.

for(j = 0; j & ltn- 1-I; J++) // Start the outer loop for, starting with J = 0, and add 1 each time until I equals N-j- 1 of the outer loop.

{//The internal circulation body starts.

if(grade[j]& lt; Grade[j+ 1]) // conditional judgment

{//If the number before the integer array is less than the number after it, execute the following statement.

temp = grade[j+ 1]; //Assign a larger number to temp.

Grade [j+ 1]= grade [j]; //Assign a smaller number to the later variable in the array.

Grade [j]= temperature; //Assign a larger number to the previous variable in the array.

}//From then on, the exchange of large and small variables is completed, and the large value is proposed.

}//End the internal loop

}//Loop outside and inside the junction to complete sorting.

Printf ("Last Sort: \ n"); //Explicitly display "Last Sort as:" on the screen and wrap.

for(I = 0; I & ltn;; I++) // Similar to the beginning of a loop.

{//Start cyclic output.

Printf("%d ",grade [i]); //Only the five values in the array are output one by one here.

}//End loop output

printf(" \ n "); //Output wraps to the screen, no effect can be seen, and it can be deleted.

}//End the main () function.