Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdlib.h>
- using namespace std;
- int mat[5][5],n,m,i=0,j=0;
- int main()
- {
- int n3;
- int n4;
- int mcd;
- int r;
- int mcm;
- cout<<"n";
- cin>>n;
- cout<<"m";
- cin>>m;
- for(i=0;i<n;i++)
- {
- for(j=0;j<m;j++)
- {
- if(mat[i+1][j+1]>mat[i][j])
- {
- r=mat[i+1][j+1];
- mat[i+1][j+1]=mat[i][j];
- mat[i][j]=r;
- }
- n3=mat[i][j];
- n4=mat[i+1][j+1];
- //Calcolo MCD
- r = n3 % n4;
- while(r!=0)
- {
- n3 = n4;
- n4 = r;
- r = n3 % n4;
- }
- mcd = n4;
- //Calcolo mcm
- mcm = (mat[i][j] * mat[i+1][j+1])/mcd;
- }
- }
- cout<< "MCD = " << mcd << " mcm = " << mcm << endl;
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement