Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <fstream>
- void avgFS(double **arr, int first, int sec);
- void minmax(double **arr, int sizeOne, int SizeTwo);
- int main() {
- std::ifstream in;
- in.open("input_file.txt");
- double arr[5][5];
- double el;
- if (in.is_open()) {
- int M = 0;
- int N = 0;
- while (in >> el) {
- if (N == 5 -1)
- {
- M++;
- }
- arr[M][N++] = el;
- }
- }
- in.close();
- avgFS(arr, 5, 5);
- minmax(arr, 5, 5);
- return 0;
- }
- void avgFS(double **arr, int first, int sec)
- {
- double sum = 0;
- int cnt = 0;
- for (int i = 0; i < first; i++)
- {
- for (int j = 0; j < sec; j++) {
- if (arr[i][j] > (-5) && arr[i][j] < 5)
- {
- sum = sum + arr[i][j];
- cnt++;
- }
- }
- }
- double sumRes = sum / cnt;
- std::cout << "Sumata ot vs elementi na masiva v diapazona -5 , 5 e : " << sumRes;
- }
- void minmax(double **arr, int sizeOne, int SizeTwo)
- {
- double tmpMin = 0;
- double tmpMax = 0;
- for (int i = 0; i < sizeOne; i++)
- {
- for (int j = 0; j < SizeTwo; j++) {
- if (arr[i][j] < tmpMin)
- {
- tmpMin = arr[i][j];
- }
- if (arr[i][j] > tmpMax)
- {
- tmpMax = arr[i][j];
- }
- }
- }
- double minMaxRes = tmpMax / tmpMin;
- std::cout << "sredno aritmetichno na minimalniq i maksimalniq indeks e : " << minMaxRes;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement