Fandom

Scratchpad

PLE:Unidad4Ejercicio02

219,495pages on
this wiki
Add New Page
Discuss this page0 Share
/*
Programa:         Unidad4Ejercicio02.cpp
Fecha:            21/11/2006
Descripción:      Intercambia los elementos de un array.

*/
#include <iostream>
#include <conio>
using namespace std;

const int NUM = 10;

void main()
{
      int num[NUM], i, tmp;

      // Leemos el array
      for(i = 0; i < NUM; i++)
      {
            cout << "Introduzca numero ";
            cin >> num[i];
      }

      // Mostramos el array
      cout << "\nArray original" << endl;
      for(i = 0; i < NUM; i++)
      {
            cout << num[i] << '\t';
      }

      // Intercambiamos
      for(i = 0; i < NUM / 2; i++)
      {
            tmp = num[i];
            num[i] = num[NUM - 1 - i];
            num[NUM - 1 - i] = tmp;
      }

      // Mostramos el array
      cout << "Array con elementos intercambiados" << endl;
      for(i = 0; i < NUM; i++)
      {
            cout << num[i] << '\t';
      }

      cin.ignore();
      cin.get();
}

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.

Also on Fandom

Random wikia