1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
|
#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;
void calc(int n, int m, int a, int x[][10], double avrg, double sum, int min, int k);
int main(){
int n, m;
double x[10][10];
int a;
double avrg;
ifstream is;
is.open("Duom.txt");
if (is.fail()){
cout << "File not found" << endl;
return -1;
}
is>>m>>n;
cout << "Matrix measurements:" << setw(5) << n << setw(5) << m << endl;
for (int i=0; i<n; i++){
for (int j=0; j<n; j++){
is>>x[i][j];
cout << "Matrix elemnt:(" << i+1 << ":" << j+1 << ")" << x[i][j] << endl;
}
}
is.close();
cout << "Matrix:" << endl;
for (int i=0; i<n; i++){
for (int j=0; j<m; j++){
cout << setiosflags(ios::fixed)
<<setiosflags(ios::showpoint)
<<setprecision(2)<< setw(12)
<< x[i][j];
}
cout<<endl;
}
ofstream rez;
rez.open("rez.txt");
rez<<"The biggest element is in" << a << "line"<< endl;
if (avrg>0){
rez<< a << "Line average is" << avrg << endl;
}
else
{
rez<<"Positive elements in" << a << "arent found" << endl;
system("pause");
return 0;
}
}
void calc(int n, int m, int a, int x[][10], double avrg, double sum, int min, int k){
min=x[0][0];
for (int i=0; i<n; i++){
for (int j=0; j<m; j++){
if (min>x[i][j]){
min=x[i][j];
a=j;
}
}
}
for (int i=0; i<n; i++){
for (int j=0; j<m; j++){
if (a==j&&x[i][j]>0){
k++;
sum+=x[i][j];
}
}
avrg=sum/k;
}
}
|