Advertisement
Guest User

Untitled

a guest
Jun 21st, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. /******************************************************************************
  2.  
  3. Online C++ Compiler.
  4. Code, Compile, Run and Debug C++ program online.
  5. Write your code in this editor and press "Run" button to compile and execute it.
  6.  
  7. *******************************************************************************/
  8.  
  9. #include <iostream>
  10. #include <math.h>
  11.  
  12. using namespace std;
  13.  
  14. const int WMAX=30, KMAX=30;
  15. struct t_zesp
  16. {
  17. float im;
  18. float re;
  19. };
  20.  
  21. void wczytaj_macierz(t_zesp A[][KMAX], int ilw, int ilk, const char* nazwa)
  22. {
  23. int i, j;
  24. for(i=0;i<ilw;i++)
  25. for(j=0;j<ilk;j++)
  26. {
  27. cout<<"Podaj"<<nazwa<<"["<<i+1<<"]["<<j+1<<"] element macierzy:"<<endl;
  28. cout<<"Czesc rzeczywista:"<<endl;
  29. cin>>A[i][j].re;
  30. cout<<"Czesc urojona:"<<endl;
  31. cin>>A[i][j].im;
  32. }
  33.  
  34. }
  35.  
  36. float f1(t_zesp W[], int il_el)
  37. {
  38. int i;
  39. float suma=0;
  40. for(i=0;i<il_el;i++)
  41. suma+= sqrt(W[i].re*W[i].re+W[i].im*W[i].im);
  42. return suma;
  43. }
  44.  
  45. void f2(t_zesp A[][KMAX], int ilw, int ilk, float *suma, int &ilosc)
  46. {int i, j;
  47. for(i=0;i<ilw;i++)
  48. for(j=0;j<ilk;j++)
  49. {*suma+=A[0][j].re+A[i][ilk-1].re;
  50. if(A[i][j].re>A[i][j].im)
  51. ilosc++;
  52. }
  53.  
  54. }
  55.  
  56.  
  57.  
  58. int main()
  59. { t_zesp A[WMAX][KMAX];
  60. int m,n,nr;
  61. cout<<"Podaj ilosc wierszy macierzy A:";
  62. cin>>m;
  63. cout<<"Podaj ilosc kolumn macierzy A:";
  64. cin>>n;
  65. wczytaj_macierz(A,m,n,"A");
  66. cout<<"Podaj numer wiersza, dla którego chcesz policzyć sume modulow "<<endl;
  67. cin>>nr;
  68. cout<<"Suma modulow wiersza "<<nr<<" wynosi "<<f1(A[nr-1],n)<<endl;
  69. float s=0;
  70. int i;
  71. f2(A,m,n,&s,i);
  72. cout<<"Suma elementow rzeczywistych pierwszego wiersza i ostatniej kolumny wynosi: "<<s<<endl;
  73. cout<<"Ilosc elementow macierzy, w ktorych czesc rzeczywista jest wieksza od urojonej wynosi: "<<i;
  74.  
  75.  
  76. return 0;
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement