Posted By

ozkriff on 09/15/08


Tagged


Versions (?)

diff


 / Published in: C
 

starting the programm...

mas1: control output: 12 7 53 13 66 45

finding max... debag info(current max): (0,0) 12 (0,1) 12 (1,0) 53 (1,1) 53 (2,0) 66 (2,1) 66

max is 66

finding min... debag info(current min): (0,0)12 (0,1)7 (1,0)7 (1,1)7 (2,0)7 (2,1)7

min is 7

finding diff...

diff is 59 Answer: max= 66 min=7 diff = 59

(program exited with code: 0)

  1. #include <stdio.h>
  2.  
  3. int main()
  4. {
  5. printf("\nstarting the programm...\n\n");
  6. int max, min, diff, i, j, mas1[3][2]={
  7. {12,7},
  8. {53,13},
  9. {66,45}};
  10. //control output
  11. printf("\nmas1: control output:\n");
  12. for (i=0;i<3;i++)
  13. {
  14. for (j=0;j<2;j++)
  15. printf("%d\t",mas1[i][j]);
  16. printf("\n");
  17. }
  18. //finding max
  19. printf("\nfinding max...");
  20. printf("\ndebag info(current max):\n");
  21. max=mas1[0][0];
  22.  
  23. for (i=0;i<3;i++)
  24. {
  25. for (j=0;j<2;j++)
  26. {
  27. max=(mas1[i][j]>max)?mas1[i][j]:max;
  28. printf("(%d,%d) %d ",i,j,max);
  29. }
  30. printf("\n");
  31. }
  32. printf("\nmax is %d\n",max);
  33. //finding min
  34. printf("\nfinding min...");
  35. printf("\ndebag info(current min):\n");
  36. min=mas1[0][0];
  37.  
  38. for (i=0;i<3;i++)
  39. {
  40. for (j=0;j<2;j++)
  41. {
  42. min=(mas1[i][j]<min)?mas1[i][j]:min;
  43. printf("(%d,%d)%d ",i,j,min);
  44. }
  45. printf("\n");
  46. }
  47. printf("\nmin is %d\n",min);
  48. //finding diff
  49. printf("\nfinding diff...\n");
  50. diff=max-min;
  51. printf("\ndiff is %d",diff);
  52. //Answer
  53. printf("\n\nAnswer: max= %d\t min=%d\t diff = %d",max,min,diff);
  54. return 0;
  55. }

Report this snippet  

You need to login to post a comment.