Răspuns :
Vezi in comentariu la primul exercitiu, ca nu ma lasa sa scriu codul in raspuns
EliminareLinii 774
#include <iostream>
using namespace std;
int b[101][101], c[101][101];
int prim (int x)
{
int p=1, t;
if (x<2) p=0;
else if (x==2) p=1;
else
{
if (x%2==0) p=0;
else
{
for (t=3; t*t<=x && p; ++t)
if (x%t==0) p=0;
}
}
return p;
}
int main()
{
int n, m, k=0, i, j;
cin >> n >> m;
for (i=1; i<=n; ++i)
for (j=1; j<=m; ++j)
cin >> b[i][j];
for (i=1; i<=n; ++i)
{
if (!prim(b[i][1]))
{
++k;
for (j=1; j<=m; ++j)
c[k][j]=b[i][j];
}
}
for (i=1; i<=k; ++i)
{for (j=1; j<=m; ++j)
cout << c[i][j] << " ";
cout << "\n";
}
return 0;
}
*********************************************************
EliminareColoane 775
#include <iostream>
#include <bitset>
using namespace std;
bitset<101>c;
int a[101][101], b[101][101];
int main()
{
int n, m, i, j, k=0;
cin >> n >> m;
for (i=1; i<=n; ++i)
for (j=1; j<=m; ++j)
{cin >> a[i][j];
if (a[i][j]==0) c[j]=1;}
for (j=1; j<=m; ++j)
if (c[j]==0)
{
++k;
for (i=1; i<=n; ++i)
b[i][k]=a[i][j];
}
for (i=1; i<=n; ++i)
{
for (j=1; j<=k; ++j)
cout << b[i][j] << " ";
cout << "\n";
}
return 0;
}