Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- int main()
- {
- struct kompleks { double re, im; };
- typedef struct kompleks kompleks;
- kompleks a[100][100] = { {0,0} };
- kompleks b[100][100] = { {0,0} };
- kompleks zbir[100][100] = { {0,0} };
- kompleks proizvod[100][100] = { {0,0} };
- int n;
- printf("Red kvadratne matrice: ");
- do{
- scanf("%d", &n);
- } while(!(n>0));
- printf("Matrica a:\n");
- for(int i = 0; i < n; i++){
- for(int j = 0; j < n; j++){
- printf("(%d,%d) Re: ", i, j);
- scanf("%lf", &a[i][j].re);
- printf("(%d,%d) Im: ", i, j);
- scanf("%lf", &a[i][j].im);
- printf("\n");
- }
- }
- printf("Matrica b:\n");
- for(int i = 0; i < n; i++){
- for(int j = 0; j < n; j++){
- printf("(%d,%d) Re: ", i, j);
- scanf("%lf", &a[i][j].re);
- printf("(%d,%d) Im: ", i, j);
- scanf("%lf", &b[i][j].im);
- printf("\n");
- }
- }
- printf("a+b:\n");
- for(int i = 0; i < n; i++){
- for(int j = 0; j < n; j++){
- zbir[i][j].re = a[i][j].re + b[i][j].re;
- zbir[i][j].im = a[i][j].im + b[i][j].im;
- printf("%lf+%lfi\t", zbir[i][j].re, zbir[i][j].im);
- }
- printf("\n");
- }
- printf("ab\n");
- for(int i = 0; i < n; i++){
- for(int j = 0; j < n; j++){
- kompleks pclan;
- kompleks aclan;
- kompleks bclan;
- for(int k = 0; k < n; k++){
- aclan = a[i][k];
- bclan = b[k][j];
- pclan.re = aclan.re * bclan.re - aclan.im * bclan.im;
- pclan.im = aclan.re * bclan.im + aclan.im * bclan.re;
- printf("\t");
- }
- proizvod[i][j] = pclan;
- printf("%lf%+lfi\t", proizvod[i][j].re, proizvod[i][j].im);
- }
- printf("\n");
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement