danb1212

Untitled

Feb 16th, 2021
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4.  
  5. int main()
  6. {
  7. int m,n,i,j;
  8. printf("Enter m,n: ");
  9. scanf("%d %d", &m, &n);
  10.  
  11. int a[2][3] = {{1, 0, m},{0, 1, n}};
  12. int c[2][3];
  13.  
  14. do
  15. {
  16. if ( a[0][2] < a[1][2] )
  17. {
  18. //swap row 1 and row 2
  19. c[0][0] = a[0][0]; c[0][1] = a[0][1]; c[0][2] = a[0][2];
  20. a[0][0] = a[1][0]; a[0][1]= a[1][1] ; a[0][2]= a[1][2];
  21. a[1][0] = c[0][0]; a[1][1] = c[0][1]; a[1][2] = c[0][2];
  22. }
  23. // row 1 = row 1 - row 2
  24. a[0][0]= a[0][0] - a[1][0]; a[0][1]=a[0][1] - a[1][1]; a[0][2]=a[0][2] - a[1][2];
  25.  
  26. } while( (a[0][2] - a[1][2]) != 0);
  27.  
  28. for ( i = 0; i <= 1; i++ )
  29. {
  30. for ( j = 0; j <= 2; j++ )
  31. {
  32. printf("a[%d][%d] = %3d\t", i,j, a[i][j] );
  33. }
  34. printf("\n");
  35. }
  36. }
  37.  
Advertisement
Add Comment
Please, Sign In to add comment