55 lines
1.4 KiB
C
55 lines
1.4 KiB
C
#include <stdio.h>
|
|
#include "complex.h" // Eigene Header-Datei für komplexe Zahlen
|
|
|
|
int main() {
|
|
double re1, im1, re2, im2;
|
|
|
|
// Eingabe der ersten komplexen Zahl
|
|
printf("1. Zahl eingeben\nRealteil: ");
|
|
scanf("%lf", &re1);
|
|
printf("Imaginärteil: ");
|
|
scanf("%lf", &im1);
|
|
|
|
// Eingabe der zweiten komplexen Zahl
|
|
printf("2. Zahl eingeben\nRealteil: ");
|
|
scanf("%lf", &re2);
|
|
printf("Imaginärteil: ");
|
|
scanf("%lf", &im2);
|
|
|
|
// Erzeugen der komplexen Zahlen als Zeiger auf Complex-Strukturen
|
|
Complex *x = createComplex(re1, im1);
|
|
Complex *y = createComplex(re2, im2);
|
|
|
|
// Berechnung der Summe, Differenz, Produkt und Quotient
|
|
Complex *sum = addComplex(x, y);
|
|
Complex *diff = subtractComplex(x, y);
|
|
Complex *prod = multiplyComplex(x, y);
|
|
Complex *quot = divideComplex(x, y);
|
|
|
|
// Ausgabe der Ergebnisse
|
|
printf("x = ");
|
|
printComplex(x);
|
|
printf("y = ");
|
|
printComplex(y);
|
|
printf("Summe: x + y = ");
|
|
printComplex(sum);
|
|
printf("Differenz: x - y = ");
|
|
printComplex(diff);
|
|
printf("Produkt: x * y = ");
|
|
printComplex(prod);
|
|
printf("Quotient: x / y = ");
|
|
printComplex(quot);
|
|
|
|
// Speicher wieder freigeben
|
|
freeComplex(x);
|
|
freeComplex(y);
|
|
freeComplex(sum);
|
|
freeComplex(diff);
|
|
freeComplex(prod);
|
|
freeComplex(quot);
|
|
|
|
return 0;
|
|
}
|
|
|
|
// Kompilieren mit:
|
|
// gcc TestComplex.c -L. -lcomplex -o TestComplex
|