Răspuns :
Răspuns: La a) (am considerat ca vei folosi doar numere naturale, avand in vedere ca ceri numere prime si patrate perfecte).Vezi ca ti-am luat n linii, m coloane ca nu-s obisnuit invers.Modifici tu daca e neaparat cum zice in enunt.
#include <iostream>
#include <cmath>
using namespace std;
unsigned int n,m,i,j,L,minim=100000,maxim_par;
unsigned int prim(unsigned int b)
{
unsigned int d;
if(b<=1)
return 0;
if(b==2)
return 1;
for(d=2;d*d<=b;d++)
if(b%d==0)
return 0;
return 1;
}
unsigned int pp(unsigned int c)
{
return (float)sqrt(c)*(float)sqrt(c)==c;
}
int main()
{
cout<<"n="; cin>>n;
cout<<"m="; cin>>m;
unsigned int A[n][m];
for(i=0;i<n;i++)
for(j=0;j<m;j++)
cin>>A[i][j];
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
if(A[i][j]<minim)
minim=A[i][j];
if(A[i][j]%2==0)
{
if(A[i][j]>maxim_par)
{
maxim_par=A[i][j];
}
}
}
}
cout<<"Elementul minim al matricii este: "<<minim<<endl;
cout<<"Elementul par maxim al matricii este: "<<maxim_par<<endl;
minim=100000;
cout<<"L="; cin>>L;
for(j=0;j<m;j++)
{
if(prim(A[L-1][j]))
{
if(A[L-1][j]<minim)
minim=A[L-1][j];
}
}
cout<<"Cel mai mic numar prim de pe linia "<<L<<" este: "<<minim;
cout<<endl;
unsigned int maxim_pp=0;
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
if(pp(A[i][j]))
{
if(A[i][j]>maxim_pp)
{
maxim_pp=A[i][j];
}
}
}
}
cout<<"Cel mai mare patrat perfect din matrice este "<<maxim_pp;
return 0;
}
Explicație: La b).La fel, ti-am luat n linii, m coloane.Modifici tu.
#include <iostream>
using namespace std;
unsigned int n,m,i,j,total_col,total_linii,ok,nrpare;
int main()
{
cout<<"n="; cin>>n;
cout<<"m="; cin>>m;
int A[n][m];
for(i=0;i<n;i++)
for(j=0;j<m;j++)
cin>>A[i][j];
for(j=0;j<m;j++)
{
ok=1;
for(i=0;i<n;i++)
{
if(A[i][j]<0)
{
ok=0;
break;
}
}
if(ok)
{
total_col++;
}
}
for(i=0;i<n;i++)
{
nrpare=0;
for(j=0;j<m;j++)
{
if(A[i][j]%2==0)
{
nrpare++;
}
}
if(nrpare>=2)
{
total_linii++;
}
}
cout<<"Numarul coloanelor care contin doar numere pozitive: "<<total_col;
cout<<endl;
cout<<"Numarul liniilor care contin cel putin 2 numere pare: "<<total_linii;
return 0;
}