C language · Normalization of complex numbers

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.