Advertisement
gosuodin

mang2chieu sort a>z

Jun 8th, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. #include<iostream>
  2. #include<string>
  3. using namespace std;
  4. void main() {
  5. int sohang, socot;
  6. cout << "Nhap so hang, so cot :";
  7. cin >> sohang >> socot;
  8. int **a = new int*[sohang];
  9. for (int i = 0; i < sohang; i++) {
  10. a[i] = new int[socot];
  11. for (int j = 0; j < socot; j++) {
  12. cout << "nhap a[" << i +1<< "][" << j+1 << "]";
  13. cin >> a[i][j];
  14. }
  15. }
  16. for (int i = 0; i < sohang; i++) {
  17. for (int j = 0; j < socot; j++) {
  18. cout << "\n\t" << a[i][j];
  19. }
  20. cout << endl;
  21. }
  22. for (int i = 0; i < sohang; i++) {
  23. for (int j = 0; j < socot; j++)
  24. for(int k=0;k<socot;k++){
  25. if ((a[i][j] < a[i][k])){
  26. int tam = a[i][k];
  27. a[i][k] = a[i][j];
  28. a[i][j] = tam;
  29. }
  30. }
  31. }
  32. cout << endl << endl;
  33. for (int i = 0; i < sohang; i++) {
  34. for (int j = 0; j < socot; j++) {
  35. cout << "\n\t"<< a[i][j];
  36. }
  37. cout << endl;
  38. }
  39. system("pause");
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement