Advertisement
nguyenhappy92

Tìm giá trị lớn thứ 2 trong ma trận

Dec 20th, 2015
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. // Tim gia tri lon thu 2 trong mang
  2. // Khai bao ham thu vien neu co
  3. #include<stdio.h>
  4. #include<conio.h>
  5. #define SIZE 100
  6. void nhap(int a[][SIZE],int &m,int &n)
  7. {
  8. scanf("%d%d",&m,&n);
  9. for(int i=0;i<m;i++)
  10. {
  11. for(int j=0;j<n;j++)
  12. {
  13. scanf("%d",&a[i][j]);
  14. }
  15. }
  16. }
  17. int max2mang(int a[][SIZE],int m,int n)
  18. {
  19. int max=a[0][0];
  20. for(int i=0;i<m;i++)
  21. {
  22. for(int j=0;j<n;j++)
  23. {
  24. if((a[i][j])>max)
  25. max=a[i][j];
  26. }
  27. }
  28. int max2=a[0][0];
  29. for(i=0;i<m;i++)
  30. {
  31. for(int j=0;j<n;j++)
  32. {
  33. if((a[i][j])!=max &&max2<max && max2<a[i][j])
  34. max2=a[i][j];
  35. }
  36. }
  37. return max2;
  38. }
  39. void main()
  40. {
  41. int a[SIZE][SIZE],m,n;
  42. nhap(a,m,n);
  43. printf("%d",max2mang(a,m,n));
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement