Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- #include <stdio.h>
- #include <stdlib.h>
- using namespace std;
- typedef struct
- {
- float real, im;
- } complexNr;
- int main()
- {
- char s[100], *p, sep[] = " +-i";
- complexNr a, b, sum, prod;
- cout << "a si b - complexe forma:x+yi" << endl;
- cout << "a este:" << endl;
- gets(s);
- int pozsim = 0;
- for (int i = 1; s[i] && !pozsim; i++)
- if (s[i] == '-')
- pozsim = i;
- if (s[0] == '-')
- a.real = -1;
- else
- a.real = 1;
- p = strtok(s, sep);
- a.real *= atof(p);
- p = strtok(NULL, sep);
- a.im = atof(p);
- if (pozsim)
- a.im = -a.im;
- cout << "b este:" << endl;
- gets(s);
- pozsim = 0;
- for (int i = 1; s[i] && !pozsim; i++)
- if (s[i] == '-')
- pozsim = i;
- if (s[0] == '-')
- b.real = -1;
- else
- b.real = 1;
- p = strtok(s, sep);
- b.real *= atof(p);
- p = strtok(NULL, sep);
- b.im = atof(p);
- if (pozsim)
- b.im = -b.im;
- sum.real = a.real + b.real;
- sum.im = a.im + b.im;
- cout << "suma: ";
- cout << sum.real;
- if (sum.im >= 0)
- cout << '+';
- cout << sum.im << 'i' << endl;
- prod.real = a.real * b.real - a.im * b.im;
- prod.im = a.real * b.im + a.im * b.real;
- cout << "produs: ";
- cout << prod.real;
- if (prod.im >= 0)
- cout << '+';
- cout << prod.im << 'i';//*/
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement