fork download
  1. #include "stdio.h"
  2. #include "stdlib.h"
  3. #include "math.h"
  4. struct c_comp //define a struct
  5. {
  6. double rmz;
  7. double imz;
  8. }c_comp;
  9. void c_comp_product(struct c_comp*,struct c_comp*,struct c_comp*); //declare a func of complex product
  10.  
  11.  
  12. int main() //main func starts
  13. {
  14. int num;
  15. struct c_comp *a1,*a2,*c; //declare pointers
  16. a1=(struct c_comp*)malloc(sizeof(struct c_comp)); //let pointers direct to menory locations
  17. a2=(struct c_comp*)malloc(sizeof(struct c_comp));
  18. c=(struct c_comp*)malloc(sizeof(struct c_comp));
  19. a1->rmz=1.0;a1->imz=1.0; //decide the values of each pointer structs
  20. a2->rmz=2.0;a2->imz=2.0;
  21. c_comp_product(a1,a2,c); //call func of complex product
  22. return 0;
  23. } //main func ends
  24.  
  25.  
  26. void c_comp_product(struct c_comp *a1,struct c_comp *a2,struct c_comp *c) //definition of the func of complex product
  27. {
  28. double p,q,s;
  29. if(a1 == NULL || a2 == NULL || c == NULL)
  30. { printf("(c_comp_product)The c_comp pointer is NULL!\n"); }
  31. p = a1->rmz*a2->rmz;
  32. q = a1->imz*a2->imz;
  33. s = (a1->rmz + a1->imz)*(a2->rmz + a2->imz);
  34. c->rmz = p - q;
  35. c->imz = s - p - q;
  36. printf("hello\n");
  37. printf("%f %f\n",c->rmz,c->imz);
  38.  
  39. }
  40.  
Success #stdin #stdout 0s 1964KB
stdin
Standard input is empty
stdout
hello
0.000000 4.000000