Laitofai

5

Nov 20th, 2018
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. //#5
  2. #include <iostream>
  3. #include <fstream>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9. ifstream fin("input.txt");
  10. if(fin.is_open() == 0){
  11. cout << "CREATE FILE WITH NAME (input.txt)";
  12. return 0;
  13. }
  14. int n = 0, temp;
  15. while(fin >> temp){
  16. n++;
  17. }
  18. fin.close();
  19. fin.open("input.txt");
  20. int arr[n];
  21. for(int i = 0; i < n; i++){
  22. fin >> arr[i];
  23. }
  24. /*
  25. Пузырьковая сортировка/Bubble sort
  26. */
  27. for(int i = 0; i < n; i++){
  28. for(int j = 0; j < n - i - 1; j++){
  29. if(arr[j] > arr[j + 1]){
  30. swap(arr[j], arr[j + 1]);
  31. }
  32. }
  33. }
  34. ofstream fout("result.txt");
  35. for(int i = 1; i <= n; i++){
  36. fout << arr[i] << " ";
  37. if(i % 10 == 0){
  38. fout << endl;
  39. }
  40. }
  41. return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment