The questions are as follows:
Train of Thought Analysis:
Write the complete program:
1/* 2 Problem description: 3 There are n sticks, and the length of the stick I is ai. Select three sticks from them to form the triangle with the longest circumference as possible. Please input 4 out of the maximum perimeter. If a triangle cannot be formed, 0 is output. 5 */6 7 # include <stdio. h> 8 # include <Stdlib. h> 9 # define MAX 100010 int max (int a, int B) {// obtain the 11 largest of the two numbers if (a> B) 12 return; 13 else14 return B; 15} 16 int main () {17 int n, ans = 0; // n is the number of digits, ans is the final longest answer 18 printf ("input n:"); 19 scanf ("% d", & n ); // obtain the number to be judged 20 int a [MAX]; 21 printf ("input % d count: \ n", n); 22 for (int m = 0; m <n; m ++) 23 {24 scanf ("% d", & a [m]); // Number of cyclic inputs to be judged 25} 26 int I, j, k; 27 // Let I <j <k, so that 28 for (I = 0; I <n; I ++) is not selected repeatedly) 29 for (j = I + 1; j <n; j ++) 30 for (k = j + 1; k <n; k ++) 31 {32 int len = a [I] + a [j] + a [k]; // perimeter 33 if (a [I] + a [j]> a [k]) & (a [j] + a [k]> a [I]) & (a [I] + a [k]> a [j]) 34 {35 ans = max (len, ans ); // replace answer 36} 37} 38 printf ("ultimate longest perimeter: % d \ n", ans); 39 40 system ("pause"); 41 return 0; 42 43}