-condition Known that n> 2 Example: If n = 100 then it will be Bruteforce system to seek and Most serious smallest number between 2 and 100. then the coding: Using pascal: MinMax program; uses crt; var A: array [2..100] of integer; var n: integer; var min, max: integer; var i: integer; begin <Clrscr>; max: - A [1]; write < 'enter the number:'>; readin <n>; for i: -2 to n do begin A [i]: = random <10>; write <A [i], ''>; <Readln <x [i]>;> end; begin if A [i] <min then min: = A [i]; end; begin min: - a [2]; if A [i]> max then max: -A [i]; end; writeln; writeln < 'max =' max>; writeln < 'min =' min>; end. results: Enter Amount: 4 (for example) 9 10 12 15 max = 15 min = 9 then the numbers are 15 and Ai Ai Min Min is 9 Time asymptotic complexity T (n) = (n - 1) + (n - 1) = 2n - 2 = O (n)
Langganan:
Postingan (Atom)
0 komentar:
Posting Komentar