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 output:
0.6+0.8i
2 5
Sample output:
0.4+0.9i
Author notes:
One: The B is defined as a double type, note that a or B can not directly into the data to be output, and then define the two output relative to the position of the data. Two: In Java, either double or float is used%f. Three: Learn a trick to let C program does not automatically end the method: while (...)! =eof) {...}.
A A, B is defined as a double type, note that you cannot directly change a or B. to the data to be output, and then define the data that corresponds to the position of the two outputs.
1#include <stdio.h>2#include <math.h>3 intMain () {4 Doubleb;5 DoubleAi,bi;6scanf"%LF%LF",&a,&b);7Ai = A/(sqrt (a*a+b*b));8Bi = B (sqrt (a*a+b*b));9printf"%.1f+%.1fi", Ai,bi);Ten}
C language · Normalization of complex numbers