Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Programa para ordenacion de datos
- #include <iostream>
- #include <fstream>
- #include <cstdlib>
- void ordenar (int n, int *a);
- using namespace std;
- int main() {
- system ("clear");
- ifstream label1 ("datos.in");
- int i, j, n = -1;
- int a[20];
- while (!label1.eof()){
- n += 1;
- label1 >> a[n];
- }
- cout << "El archivo tiene " << n << " valores\n";
- label1.close();
- cout << "Serie desordenada de valores\n";
- for (i=0; i < n; i++){
- cout << a[i] << " ";
- }
- cout << "\n";
- ordenar(n,a); //funcion ordenar
- cout << "Serie ordenada de valores\n";
- for (i=0; i < n; i++){
- cout << a[i] << " ";
- }
- cout << "\n";
- return 0;
- }
- void ordenar (int n, int *a){
- int i, j, mayor;
- for (i=0; i < n-1; i++){
- for (j=0; j < n-1; j++){
- if(a[j] > a[j+1]){
- mayor = a[j];
- a[j] = a[j+1];
- a[j+1] = mayor;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement