Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //#5
- #include <iostream>
- #include <fstream>
- using namespace std;
- int main()
- {
- ifstream fin("input.txt");
- if(fin.is_open() == 0){
- cout << "CREATE FILE WITH NAME (input.txt)";
- return 0;
- }
- int n = 0, temp;
- while(fin >> temp){
- n++;
- }
- fin.close();
- fin.open("input.txt");
- int arr[n];
- for(int i = 0; i < n; i++){
- fin >> arr[i];
- }
- /*
- Пузырьковая сортировка/Bubble sort
- */
- for(int i = 0; i < n; i++){
- for(int j = 0; j < n - i - 1; j++){
- if(arr[j] > arr[j + 1]){
- swap(arr[j], arr[j + 1]);
- }
- }
- }
- ofstream fout("result.txt");
- for(int i = 1; i <= n; i++){
- fout << arr[i] << " ";
- if(i % 10 == 0){
- fout << endl;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment