# Thread: A square matrix with complex numbers

1. ## A square matrix with complex numbers

Alright, I've been working on complex numbers, and I have the structure for it...
Code:
```struct cmplx {
double r;
double i;
};```
Now, if I wanted to make a matrix with cmplx numbers, could I just...
Code:
```int main(){
cmplx a,b,c,d, A[2][2];
a.r=0
a.i=0
b.r=0
b.i=0
c.r=0
c.i=0
d.r=0
d.i=0
A[0][0]=a;
A[0][1]=b;
A[1][0]=c;
A[1][1]=d;```
I'm guessing this is how to do it, but I don't think it will print as number+number*i.
Any ideas to do this? Any ideas to get a simple format for printing out complex numbers?

2. You will need to write your own print function.
Btw, C99 supports complex number!
Code:
```#include <complex.h>

int main(void)
{
complex double c = 3 + 4*I;
complex double z = 10 + 5.0 * I;
z *= c ;    // complex arith !
z = cexp(z);
printf("%g %g\n",creal(z),cimag(z) );
return 0;
}```

3. like....
Code:
```void printcmplxmtrx(A[2][2]){
printf("A[1][1]=%lf+%lf*i", a.r, a.i);
.
.
.
}```
?

4. microsoft visual studio express 2010 doesn't have complex.h

5. The way you declared it, you'd need the word "struct" preceding the actual definitions of your variables. You should look up how to use "typedef".

6. My struct is ok, atleast with just complex numbers. I can't figure out how to get my array's to hold complex numbers

Popular pages Recent additions