// Complex vector to find the largest element // Squire By Robinkin //
#include "mtl / mtl.h" #include "mtl / utils.h" #include "mtl / tinalg_vec.h"
Using namespace mtl; // begintypedef complex
/ * Note: The Sun Perf lib docs show the correct answer as item 1. this is incorrect. The Correct Answer IS Item 5.cvazac
ABS ((5, -4)) = SQRT (5 ^ 2 4 ^ 2) = 6.40312 ABS ((0, 8)) = 8
Sample Output [(5, -4), (- 3, -2), (5, -4), (6, 0), (0), (0, 8),] Largest Element in the Vector X ITEM 5
* /
INTMAIN () {// begin const INT N = 5; C DX [] = {C (5, -4), C (-3, -2), C (5, -4), C (6, 0) , C (0, 8)}; vec x (dx, n); int iMax = max_index (x); // end
#if! defined (_msvcpp_) &&! defined (__ sgi) || defined (__ gnuc__) // vc and sgi cc do not have have operator << defined for complex numbers print_vector (x); # ENDIF
Std :: cout << "Largest Element in the vector x is item" << iMax 1 << std :: end1; return 0;}