Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int n,m,vet[5][5],sd1,sd2;
- int primi(int mat[] [5],int dim1,int dim2)
- {
- int c=0;
- int s=0;
- for(int i=0;i<dim1;i++)
- {
- for(int j=0;j<dim2;j++)
- {
- for(c=mat[i][j]-1;c>1;c--)
- {
- if(mat[i][j]%c==0)
- {
- cout<<"No primo"<<endl;
- break;
- }
- }
- if(c<=1)
- {
- s=s+mat[i][j];
- }
- }
- }
- return s;
- }
- int diagonali(int mat[][5],int dim1,int dim2,int& sdp)
- {
- int sds=0;
- sdp=0;
- for(int i=0;i<dim1;i++)
- {
- for(int j=0;i<dim2;j++)
- {
- if(i==j)
- {
- sdp=sdp+mat[i][j];
- }
- }
- }
- int j=dim2-1;
- for(int i=0;i<dim1;i++)
- {
- sds=sds+mat[i][j];
- j--;
- }
- return sds;
- }
- int main()
- {
- do{
- cout<<"n";
- cin>>n;
- cout<<"m";
- cin>>m;
- }while(n!=m);
- for(int i=0;i<n;i++)
- {
- for(int j=0;j<m;j++)
- {
- cout<<"Inserisci elemento"<<i<<j<<endl;
- cin>>vet[i][j];
- }
- int s= primi(vet,n,m);
- sd2= diagonali(vet,n,m,sd1);
- cout<<s<<endl;
- cout<<sd1<<endl;
- cout<<sd2;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement