Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - Input any integer 10 from the keyboard, and output the maximum value and the second maximum value. How to use C++ programming?
Input any integer 10 from the keyboard, and output the maximum value and the second maximum value. How to use C++ programming?
# include & ltstdio.h & gt

void max(int a[],int n,int *pmax 1,int *pmax2)

{

int I;

* pmax 1 = * pmax 2 = a[0]; //The initial value is the first element

for(I = 1; I & ltn;; I++) // Loop through the entire array.

{

if(a[I]& gt; * pmax 1){ * pmax 2 = * pmax 1; * pmax 1 = a[I]; }//If the current number is greater than the maximum number, assign it to the maximum number.

else if(a[I]& gt; * pmax 2)* pmax 2 = a[I]; //If it is not the largest number, it is greater than the second largest number, and it is assigned to this number.

}

}

int main (){

int a[ 10],pmax 1,pmax2,I;

for(I = 0; I< 10; i++)

scanf("%d ",& ampa[I]);

Maximum value (a, 10, & pmax1. pmax 2);

printf("max 1=%d,max2=%d\n ",pmax 1,pmax 2);

Returns 0;

}