Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- /**
- * Se ingresa por teclado en un vector de 10 elementos, 9 números todos distintos entre sí y ordenados de menor a mayor.
- * Se pide ingresar otro valor e insertarlo en el orden correspondiente y desplazar todos los elementos un lugar.
- *
- */
- int main(){
- const int CANT = 10;
- int array[CANT],i, numero, siguiente;
- bool ordenado = 0;
- cout << "Ingrese 9 numeros distintos, de menor a mayor: " <<endl;
- for(i=0; i<CANT-1;i++){
- cin >> array[i];
- }
- cout << "Ingrese un numero que se encuentre entre el menor y el mayor de listado anterior: ";
- cin >> numero;
- for(i=0; i<CANT;i++){
- if(ordenado){
- int temp=array[i];
- array[i]=siguiente;
- siguiente = temp;
- }
- else if(array[i]>numero){
- int temp = array[i];
- siguiente = temp;
- array[i] = numero;
- ordenado = 1;
- }
- }
- cout << "Se ordenó el listado: " << endl;
- for(i=0; i<CANT;i++){
- cout << array[i] << ", ";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement