Working with complex numbers : Complex « Data Type « C Tutorial

C Tutorial
1. Language
2. Data Type
3. String
4. printf scanf
5. Operator
6. Statement
7. Array
8. Function
9. Structure
10. Pointer
11. Memory
12. Preprocessor
13. File
14. Data Structure
15. Search Sort
16. Wide Character String
17. assert.h
18. ctype.h
19. math.h
20. setjmp.h
21. signal.h
22. stdio.h
23. stdlib.h
24. string.h
25. time.h
26. wctype.h
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
C Tutorial » Data Type » Complex 
2. 32. 1. Working with complex numbers
#include <complex.h>
#include <stdio.h>

int main(void)
{
  double complex cx = 1.0 3.0*I;
  double complex  cy = 1.0 4.0*I;
  printf("Working with complex numbers:");
  printf("\nStarting values: cx = %.2f%+.2fi  cy = %.2f%+.2fi", creal(cx), cimag(cx), creal(cy), cimag(cy));

  double complex  sum = cx+cy;
  printf("\n\nThe sum cx + cy = %.2f%+.2fi", creal(sum),cimag(sum));

  double complex  difference = cx-cy;
  printf("\n\nThe difference cx - cy = %.2f%+.2fi", creal(difference),cimag(difference));

  double complex product = cx*cy;
  printf("\n\nThe product cx * cy = %.2f%+.2fi",creal(product),cimag(product));

  double complex quotient = cx/cy;
  printf("\n\nThe quotient cx / cy = %.2f%+.2fi", creal(quotient),cimag(quotient));

  double complex conjugate = conj(cx);
  printf("\n\nThe conjugate of cx =  %.2f%+.2fi", creal(conjugate,cimag(conjugate));
    return 0;
}
Working with complex numbers:
Starting values: cx = 1.00+3.00i  cy = 1.00-4.00i

The sum cx + cy = 2.00-1.00i

The difference cx - cy = 0.00+7.00i

The product cx * cy = 13.00-1.00i

The quotient cx / cy = -0.65+0.41i

The conjugate of cx =  1.00-3.00i
2. 32. Complex
2. 32. 1. Working with complex numbers
w_ww.___j__av___a___2__s___.___c___om | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.