2Danke
ERLEDIGT
JA
JA
ANTWORTEN
3
3
ZUGRIFFE
216
216
EMPFEHLEN
-
04.11.11 16:57 #1
- Registriert seit
- Jun 2011
- Beiträge
- 76
Hallo,
ich hab ein Programm geschrieben das Komplexe Zahlen addiert, subthariert und multipliziert.
Aber nur tritt einer Fehlermeldung(oder so) auf, wenn ich mit Einzelschritt durchgehe.
Das Programm besteht aus einem H-File und 2 C-Files.
Header-File:
Code cpp:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
struct complex_struct { double real; double imag; }; typedef struct complex_struct complex; complex c_add(complex a, complex b); complex c_sub(complex a, complex b); complex c_multi(complex a, complex b); void c_print_add(complex a); void c_print_sub(complex a); void c_print_multi(complex a);
1. C-File(Unterprogramme):
Code cpp:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
#include "compl.h" #include <stdio.h> complex c_add(complex a, complex b) { complex result; result.real = a.real + b.real; result.imag = a.imag + b.imag; return result; } void c_print_add(complex a) { printf("%lf + j%lf",a.real,a.imag); } complex c_sub(complex a, complex b) { complex result; result.real = a.real - b.real; result.imag = a.imag - b.imag; return result; } void c_print_sub(complex a) { printf("%lf - j%lf",a.real,a.imag); } complex c_multi(complex a, complex b) { complex result; result.real = (a.real*b.real) + ((-1)*(a.imag*b.imag)); result.imag = (a.imag*b.real) + (b.imag*a.real); } void c_print_multi(complex a) { printf("%lf j%lf",a.real,a.imag); }
2.C-file(Hauptprogramm):
Code cpp:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
#include <stdio.h> #include "compl.h" void main() { complex c1 = {4.0,5.9}; complex c2; complex c3; c2.real=7; c2.imag=0.1; c3 = c_add(c1,c2); c_print_add(c1); printf(" + "); c_print_add(c2); printf(" = "); c_print_add(c3); printf("\n"); c2.real=7; c2.imag=0.1; c3 = c_sub(c1,c2); c_print_sub(c1); printf(" - "); c_print_sub(c2); printf(" = "); c_print_sub(c3); printf("\n"); c2.real=7; c2.imag=0.1; c3 = c_multi(c1,c2);//hier kommt die Fehlermeldung(siehe pic) c_print_multi(c1); printf(" * "); c_print_multi(c2); printf(" = "); c_print_multi(c3); printf("\n"); }
Was könnte es da haben?
Danke im voraus!
mfg googlehupf
-
Hallo,
du hast in c_multi vergessen, einen Wert zurückzugeben. Hat dich dein Compiler etwa nicht darauf hingewiesen!?
\edit: %lf gibt es bei printf nicht, es sollte einfach nur %f heißen.
Grüße,
Matthias„Gib einem Menschen einen Fisch, und er wird für einen Tag satt. Lehre ihn Fischen, und er wird ein Leben lang satt.“
“For every complex problem, there is an answer that is short, simple and wrong.”
“Pessimism is safe, but optimism is a lot faster!”
Aktuelles Coding Quiz: #17 - Wörter kreuz und quer
-
04.11.11 18:03 #3
- Registriert seit
- Jun 2011
- Beiträge
- 76
Ok, stimmt danke

Ich hab ein Problem mit der komplexen Division, ich weis nicht wie ich die schreiben könnte..., weil wenn wir z.B haben 2+5,9j/7+0,5j dann müsste man konjungiert komplex erweitern und das ist irgendwie zu aufwendig zu programmieren finde ich.. gibts da keine einfachere Lösung?
-
Was ist denn daran zu aufwändig? Die Multiplikation hast du doch auch geschafft. Mehr musst du für die Division auch nicht beherrschen.
Grüße,
Matthias„Gib einem Menschen einen Fisch, und er wird für einen Tag satt. Lehre ihn Fischen, und er wird ein Leben lang satt.“
“For every complex problem, there is an answer that is short, simple and wrong.”
“Pessimism is safe, but optimism is a lot faster!”
Aktuelles Coding Quiz: #17 - Wörter kreuz und quer
Ähnliche Themen
-
Ausnahme für IE6 und der W3C Validator
Von Eagle-PsyX- im Forum HTML & XHTMLAntworten: 13Letzter Beitrag: 25.10.08, 23:13 -
Einstellungen für die Ausnahme SQLException
Von JSteinhilber im Forum JavaAntworten: 1Letzter Beitrag: 07.02.08, 20:13 -
Ausnahme bei new
Von jokey2 im Forum VisualStudio & MFCAntworten: 5Letzter Beitrag: 17.09.06, 12:08 -
Order by Ausnahme
Von piti66 im Forum Relationale DatenbanksystemeAntworten: 5Letzter Beitrag: 13.01.06, 11:02 -
[C++] - Unbehandelte Ausnahme...
Von Rofi im Forum C/C++Antworten: 1Letzter Beitrag: 29.10.05, 00:28





Zitieren


Login






