Created
September 28, 2026 07:22
-
-
Save thinkphp/ad369a00e5dfa85a55a777892bafbeaf to your computer and use it in GitHub Desktop.
Laborator1 Numere Complexe
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| Numere complexe: | |
| parte reala | |
| parte imaginara | |
| z1 = a + bi | |
| z2 = c + di | |
| unhde i^1 = -1 | |
| adunare | |
| z1 + z2 = (a + c) + (b + d)i | |
| scadere | |
| z1 - z2 = (a - c) + (b - d)i | |
| inmultire: | |
| z1 * z2 = (a+bi)(c+di)= | |
| ac + adi + bci + bdi^2 | |
| (ac - bd) + (ad + bc)i | |
| impartire: | |
| a + bi c - di | |
| ------ | |
| c + di c - di | |
| ac + bd bc - ad | |
| -------- + --------- i | |
| c^2 + d^2 c^2 + d^2 | |
| z1 = a + bi | |
| z2 = c + di | |
| ////////////////////////////////////// | |
| z1 = a->re + a->im | |
| z2 = b->re + b->im | |
| ////////////////////////////////////// | |
| */ | |
| #include <stdio.h> | |
| typedef struct { | |
| float re;//parte reala | |
| float im;//parte imaginara | |
| } COMPLEX; | |
| void adunare(const COMPLEX *a, const COMPLEX *b, COMPLEX *c) { | |
| c->re = a->re + b->re; | |
| c->im = a->im + b->im; | |
| } | |
| void scadere(const COMPLEX *a, const COMPLEX *b, COMPLEX *c) { | |
| c->re = a->re - b->re; | |
| c->im = a->im - b->im; | |
| } | |
| // | |
| void inmultire(const COMPLEX *a, const COMPLEX *b, COMPLEX *c) { | |
| float re = a->re * b->re - a->im * b->im; | |
| float im = a->re * b->im + a->im * b->re; | |
| c->re = re; | |
| c->im = im; | |
| } | |
| int impartire(const COMPLEX *a, const COMPLEX *b, COMPLEX *c) { | |
| float x = b->re * b->re + b->im * b->im; | |
| if(x == 0) { | |
| return 1; | |
| } | |
| c->re = (a->re * b->re + a->im * b->im)/ x; | |
| c->im = (a->im * b->re - a->re * b->im)/ x; | |
| return 0; | |
| } | |
| int citeste(const char *name, COMPLEX *z) { | |
| printf("%s.re = ", name); | |
| if(scanf("%f", &z->re) != 1) { | |
| return 0; | |
| } | |
| printf("%s.im = ", name); | |
| if(scanf("%f", &z->im) != 1) { | |
| return 0; | |
| } | |
| return 1; | |
| } | |
| // +,-,*,/ | |
| void afiseaza(const COMPLEX *a, char op, const COMPLEX *b, const COMPLEX *c) { | |
| printf("\n(%.2f + i*%.2f) %c (%.2f + i*%.2f) = %.2f + i*%.2f\n", a->re, a->im, op, b->re, b->im, c->re, c->im); | |
| } | |
| int main(int argc, char const *argv[]) | |
| { | |
| COMPLEX a, b, c; | |
| char ch = 'D'; // | |
| while(ch == 'D' || ch == 'd') { | |
| printf("\nIntroduceti primul numar complex\n"); | |
| if(!citeste("a", &a)) { | |
| printf("Valoare invalida\n"); | |
| return 1; | |
| } | |
| if(!citeste("b", &b)) { | |
| printf("Valoare invalida\n"); | |
| return 1; | |
| } | |
| //&a, &b, &c = adresele variabilelor...functiile lucreaza direct pe ele | |
| adunare(&a, &b, &c); | |
| afiseaza(&a, '+', &b, &c); | |
| scadere(&a, &b, &c); | |
| afiseaza(&a, '-', &b, &c); | |
| inmultire(&a, &b, &c); | |
| afiseaza(&a, '*', &b, &c); | |
| if(impartire(&a, &b, &c) == 0) { | |
| afiseaza(&a, '/', &b, &c); | |
| } else { | |
| printf("\nImpartire la ZERO!\n"); | |
| } | |
| printf("\nContinuati ? DA = D \n NU = alt caracter: "); | |
| if(scanf(" %c", &ch) != 1) { | |
| ch = 'n'; | |
| } | |
| } | |
| return 0; | |
| } | |
| /* | |
| ADT | |
| Fractie | |
| f1 = | |
| f2 = | |
| typedef struct { | |
| int numarator; | |
| int numitor; | |
| } FRACTIE | |
| FRACTIE f1, f2 | |
| citeste(&f1) | |
| citeste(&f2) | |
| adunare(&f1,&f2,&f3) | |
| afisare() | |
| scadere(&f1,&f2,&f3) | |
| afisare() | |
| inmultire(&f1,&f2,&f3) | |
| afisare() | |
| impatire(&f1,&f2,&f3) | |
| */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment