Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /******************************************************************************
- Online C++ Compiler.
- Code, Compile, Run and Debug C++ program online.
- Write your code in this editor and press "Run" button to compile and execute it.
- *******************************************************************************/
- #include <iostream>
- #include <math.h>
- using namespace std;
- const int WMAX=30, KMAX=30;
- struct t_zesp
- {
- float im;
- float re;
- };
- void wczytaj_macierz(t_zesp A[][KMAX], int ilw, int ilk, const char* nazwa)
- {
- int i, j;
- for(i=0;i<ilw;i++)
- for(j=0;j<ilk;j++)
- {
- cout<<"Podaj"<<nazwa<<"["<<i+1<<"]["<<j+1<<"] element macierzy:"<<endl;
- cout<<"Czesc rzeczywista:"<<endl;
- cin>>A[i][j].re;
- cout<<"Czesc urojona:"<<endl;
- cin>>A[i][j].im;
- }
- }
- float f1(t_zesp W[], int il_el)
- {
- int i;
- float suma=0;
- for(i=0;i<il_el;i++)
- suma+= sqrt(W[i].re*W[i].re+W[i].im*W[i].im);
- return suma;
- }
- void f2(t_zesp A[][KMAX], int ilw, int ilk, float *suma, int &ilosc)
- {int i, j;
- for(i=0;i<ilw;i++)
- for(j=0;j<ilk;j++)
- {*suma+=A[0][j].re+A[i][ilk-1].re;
- if(A[i][j].re>A[i][j].im)
- ilosc++;
- }
- }
- int main()
- { t_zesp A[WMAX][KMAX];
- int m,n,nr;
- cout<<"Podaj ilosc wierszy macierzy A:";
- cin>>m;
- cout<<"Podaj ilosc kolumn macierzy A:";
- cin>>n;
- wczytaj_macierz(A,m,n,"A");
- cout<<"Podaj numer wiersza, dla którego chcesz policzyć sume modulow "<<endl;
- cin>>nr;
- cout<<"Suma modulow wiersza "<<nr<<" wynosi "<<f1(A[nr-1],n)<<endl;
- float s=0;
- int i;
- f2(A,m,n,&s,i);
- cout<<"Suma elementow rzeczywistych pierwszego wiersza i ostatniej kolumny wynosi: "<<s<<endl;
- cout<<"Ilosc elementow macierzy, w ktorych czesc rzeczywista jest wieksza od urojonej wynosi: "<<i;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement