well assume i follow dwk's method..
changing my coding from typedef struct to struct complex
now i got errors when i want to convert my codes here...
can anyone help me if i want to change the first to the second in my following codes
Code:
#include<stdio.h>
#include<math.h>
typedef struct{double r;
double i;} COMPLEX;
COMPLEX c_add(COMPLEX za, COMPLEX zb);
main()
{
COMPLEX z1, z2, z3, *pz;
/******************************************************************
* Get two complex numbers *
******************************************************************/
printf("enter the values of z1 and z2:\n z1?:\n");
scanf("%lf%lf",&z1.r, &z1.i);
printf("z2:\n");
scanf("%lf%lf",&z2.r,&z2.i);
pz = &z3;
*pz = c_add(z1,z2);
printf("%lf + %lfi\n",pz->r,pz->i);
}
/******************************************************************
* Returns sum of complex numbers za and zb
******************************************************************/
COMPLEX c_add(COMPLEX za, COMPLEX zb)
{
COMPLEX sum;
sum.r = za.r + zb.r;
sum.i = za.i + zb.i;
return (sum);
}