Skip to content

Instantly share code, notes, and snippets.

Created December 5, 2013 19:41
Show Gist options
  • Save anonymous/7812489 to your computer and use it in GitHub Desktop.
Save anonymous/7812489 to your computer and use it in GitHub Desktop.
#include "stdafx.h"
#include <iomanip>
#include <iostream>
#include <fstream>
using namespace std;
const char filens[]="D://1.txt"; //ПУТЬ ДО ФАЙЛА
const int n=6;
const int m=6;
void printm(int **mas, int n, int m)
{
for(int i=0; i<=n-1; i++)
{
for(int k=0; k<=m-1; k++)
{
cout<<mas[i][k]<<" ";
}
cout<<endl;
}
}
void result(int **mas, int m, int n)
{
int min=0,t=0,b=0,p=0,o=0;
for(int i=0; i<=m-1; i++)
{
for(int k=0; k<=n-1; k++)
{
for(int g=0; g<=m-1; g++)
{
if (mas[i][k]>mas[i][g])
{
t=1;
}
if(mas[i][k]<mas[i][g])
{
p=1;
}
}
if (t==0)
{
for (int z=0; z<=m-1; z++)
{
if(mas[i][k]<mas[z][k])
{
b=1;
}
}
}
if (p==0)
{
for (int z=0; z<=m-1; z++)
{
if(mas[i][k]>mas[z][k])
{
o=1;
}
}
}
if(((p==0)&&(o==0))||((t==0)&&(b==0)))
{
cout<<endl;
cout<<"mas["<<i+1<<"]["<<k+1<<"] является и максимальным и минимальным эл-ом";
}
p=0; t=0;
b=0; o=0;
}
}
}
int _tmain(int argc, _TCHAR* argv[])
{
int temp,i=0,k=0;
setlocale(LC_ALL, "Rus");
srand(time(0));
ifstream FILE;
FILE.open(filens,ios::in);
if (FILE==NULL)
{
cout<<"Файла не существует";
_sleep(9999);
return 0;
} else
{
int **mas;
mas=new int*[n];
for(int q=0; q<= n-1; q++)
{
mas[q]=new int[m];
}
i=0; k=0;
while(!FILE.eof())
{
FILE>>temp;
mas[i][k]=temp;
k++;
if (k==m)
{
k=0;
i++;
}
}
printm(mas,m,n);
result(mas,m,n);
}
_sleep(99999);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment