Algorithm improves complex normalization time limit: 1.0s memory limit: 512.0MB The function normalize is written, the complex number is normalized, the even if complex is a+bi, and the normalized result is a/sqrt (a*a+b*b) + i*b/sqrt (a*a+b*b). It may be necessary to use struct pointer types as function parameters. Where the real and imaginary parts are entered by the keyboard, the output is normalized, and if the real or imaginary part of the normalized result is a decimal, a decimal is reserved.
Sample input: (Format description: 3 4 is the real and imaginary parts of real numbers separated by spaces respectively)
3 4 Sample Output 0.6+0.8i Example input 2 5 sample output 0.4+0.9i
1#include <iostream>2#include <cstdio>3#include <cstring>4#include <algorithm>5#include <cmath>6 using namespacestd;7 intMain ()8 {9 Doubleb;Ten Doublea1,b1; One while(~SCANF ("%LF%LF",&a,&b)) A { -A1=A/SQRT (a*a+b*b); -B1=B/SQRT (a*a+b*b); theprintf"%.1lf+%.1lfi\n", A1,B1); - } - return 0; -}
Algorithm to improve the normalization of complex numbers