0% found this document useful (0 votes)
7 views

Prob

The document contains C++ code that reads in a 2D array of integers and performs several operations on it including counting even numbers in each row and column, summing diagonals and rows/columns, and finding minimums and maximums. It also sorts and sums elements of a 1D array.

Uploaded by

ce
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Prob

The document contains C++ code that reads in a 2D array of integers and performs several operations on it including counting even numbers in each row and column, summing diagonals and rows/columns, and finding minimums and maximums. It also sorts and sums elements of a 1D array.

Uploaded by

ce
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include <iostream>

#include <fstream>

using namespace std;

int main()
{
int s,i,n,j,a[100][100],nr,s1,s2,mn,mx,v[100],aux;
cin >> n;
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)cin >> a[i][j];
for(i=1;i<=n;i++)
{
nr=0;
for(j=1;j<=n;j++)
if(a[i][j]%2==0) nr++;
cout << "linia" << " " << i<< "are"<< " " << nr<< " " << "cutii pline cu
prajituri"<< endl;
}
for(i=1;i<=n;i++)

{ for(j=1;j<=n;j++)
if(i==j) s=s+a[i][j];
}
cout << "cantitatea de prajituri de pe diagonala principala este " << " "
<< s;
cout << endl;
for(j=1;j<=n;j++)
{
mn=a[1][j];
for(i=1;i<=n;i++)
if(a[i][j] <mn)mn=a[i][j];
cout << "coloana " << " " << j<< " " << "are cea mai mica cantitate de
prajituri de " << " " << mn << " " << "cutii"<<" "<<endl;
}
for(j=1;j<=n;j++)
{
for(i=1;i<=n;i++) s1=s1+a[i][n];
cout << " cantitatea de prajituri de pe ultima coloana " << " " << s1;
cout << endl;
}
for(i=1;i<=n;i++)
{
mx=a[i][1];
for(j=1;j<=n;j++)
if(a[i][j] > mx) mx = a[i][j];
cout << "linia " << " " << i << " " << "are cea mai mare cantitate de
prajituri de " << " " << mx << " " << "cutii"<< endl;
}

for(i=0;i<n;i++)
cin >> v[i];
for(i=0;i<n-1;i++)
for(j=i+1;j<n;j++)
if (v[i]%2==0 && v[j]%2==0)
if(v[i]<v[j])
{
aux=v[i];
v[i]=v[j];
v[j]=aux;
}
for(i=0;i<n;i++)
cout << v[i] << " ";
for(i=0;i<n;i++)
{
if(i%2==0)
if(v[i]%5==0) s2=s2+v[i];
}
cout << s2 << endl;

return 0;
}

4
6 4 7 9
3 2 7 4
4 1 8 6
4 9 5 3

You might also like