Advertisement
Guest User

Untitled

a guest
Dec 9th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main()
  5. {
  6.  
  7. struct kompleks { double re, im; };
  8. typedef struct kompleks kompleks;
  9.  
  10. kompleks a[100][100] = { {0,0} };
  11. kompleks b[100][100] = { {0,0} };
  12.  
  13. kompleks zbir[100][100] = { {0,0} };
  14. kompleks proizvod[100][100] = { {0,0} };
  15.  
  16. int n;
  17. printf("Red kvadratne matrice: ");
  18. do{
  19. scanf("%d", &n);
  20. } while(!(n>0));
  21.  
  22. printf("Matrica a:\n");
  23. for(int i = 0; i < n; i++){
  24. for(int j = 0; j < n; j++){
  25. printf("(%d,%d) Re: ", i, j);
  26. scanf("%lf", &a[i][j].re);
  27. printf("(%d,%d) Im: ", i, j);
  28. scanf("%lf", &a[i][j].im);
  29. printf("\n");
  30. }
  31. }
  32. printf("Matrica b:\n");
  33. for(int i = 0; i < n; i++){
  34. for(int j = 0; j < n; j++){
  35. printf("(%d,%d) Re: ", i, j);
  36. scanf("%lf", &a[i][j].re);
  37. printf("(%d,%d) Im: ", i, j);
  38. scanf("%lf", &b[i][j].im);
  39. printf("\n");
  40. }
  41. }
  42. printf("a+b:\n");
  43. for(int i = 0; i < n; i++){
  44. for(int j = 0; j < n; j++){
  45. zbir[i][j].re = a[i][j].re + b[i][j].re;
  46. zbir[i][j].im = a[i][j].im + b[i][j].im;
  47. printf("%lf+%lfi\t", zbir[i][j].re, zbir[i][j].im);
  48. }
  49. printf("\n");
  50. }
  51. printf("ab\n");
  52. for(int i = 0; i < n; i++){
  53. for(int j = 0; j < n; j++){
  54. kompleks pclan;
  55. kompleks aclan;
  56. kompleks bclan;
  57. for(int k = 0; k < n; k++){
  58. aclan = a[i][k];
  59. bclan = b[k][j];
  60. pclan.re = aclan.re * bclan.re - aclan.im * bclan.im;
  61. pclan.im = aclan.re * bclan.im + aclan.im * bclan.re;
  62.  
  63. printf("\t");
  64. }
  65.  
  66. proizvod[i][j] = pclan;
  67. printf("%lf%+lfi\t", proizvod[i][j].re, proizvod[i][j].im);
  68. }
  69. printf("\n");
  70. }
  71. return 0;
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement