Advertisement
Guest User

Untitled

a guest
May 21st, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdlib.h>
  3. using namespace std;
  4. int mat[5][5],n,m,i=0,j=0;
  5. int main()
  6. {
  7.  
  8. int n3;
  9. int n4;
  10. int mcd;
  11. int r;
  12. int mcm;
  13.  
  14. cout<<"n";
  15. cin>>n;
  16. cout<<"m";
  17. cin>>m;
  18. for(i=0;i<n;i++)
  19. {
  20. for(j=0;j<m;j++)
  21. {
  22. if(mat[i+1][j+1]>mat[i][j])
  23. {
  24. r=mat[i+1][j+1];
  25. mat[i+1][j+1]=mat[i][j];
  26. mat[i][j]=r;
  27. }
  28. n3=mat[i][j];
  29. n4=mat[i+1][j+1];
  30.  
  31. //Calcolo MCD
  32. r = n3 % n4;
  33. while(r!=0)
  34. {
  35. n3 = n4;
  36. n4 = r;
  37. r = n3 % n4;
  38. }
  39. mcd = n4;
  40. //Calcolo mcm
  41.  
  42. mcm = (mat[i][j] * mat[i+1][j+1])/mcd;
  43.  
  44. }
  45. }
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54. cout<< "MCD = " << mcd << " mcm = " << mcm << endl;
  55. system("pause");
  56. return 0;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement