LoginSignup
1
1

More than 5 years have passed since last update.

cで複素数

Posted at

概要

cで複素数やってみた。

サンプルコード

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <complex.h>

#define NCprintf(a)     (printf(#a " = "),Cprintf(a))
void Cprintf(complex double z)
{
    printf ("%f %+fi\n", creal(z), cimag(z));
}
int main(void)
{
    double complex z = 1 + 2i;
    double complex c;
    NCprintf(z);
    NCprintf(z * z);
    NCprintf(I);
    NCprintf(z * I);
    NCprintf(z + (4 + 2i));
    NCprintf(conj(z));
    printf ("cabs(z) = %f\n", cabs(z));
    printf ("carg(z) = %f\n", (double) carg(z));
    NCprintf(sin(z));
    NCprintf(exp(z));
    c = 3 + 4i;
    NCprintf(c);
    return (0);
}

成果物

以上。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1