Q1:查找一个整数数组中第二大的数

View Code
 1 const int MINNUMBER = -32767; 
 2 int find_sec_max(int data[],int count) 
 3 { 
 4     int maxnumber = data[0]; 
 5     int sec_max = MINNUMBER; 
 6     for(int i = 1;i < count; i++) 
 7     { 
 8         if(data[i] > maxnumber) 
 9         { 
10             sec_max=maxnumber;
11             maxnumber=data[i];
12             
13         } 
14         else 
15         { 
16             if(data[i] > sec_max)
17             {
18                 sec_max=data[i];
19             }
20                 
21         } 
22     } 
23     return sec_max; 
24 } 

Q2:分解质因数

View Code
 1 #include <iostream.h>
 2 
 3 void prim(int m,int n) 
 4 { 
 5     if(m>n) 
 6     { 
 7         while(m%n!=0)
 8         {
 9             n++;
10         }
11         m/=n; 
12         prim(m,n); 
13         cout<<n<<endl; 
14     } 
15 } 
16 void main() 
17 { 
18     int n = 18; 
19     prim(n,2); 
20 }