Fandom

Scratchpad

PLE:Unidad5Ejercicio2

219,566pages on
this wiki
Add New Page
Discuss this page0 Share
/*
Programa:       Unidad5Ejercicio01.cpp
Descripción:    Declara un array de 10 enteros e intercambia el
                orden de los elementos
*/
#include <iostream>
#include <cstdlib>
using namespace std;

void main ()
{
        const int MAX = 10;
        int num[MAX], i, tmp;

        srand(time(NULL));

        // Generamos numeros aleatorios
        for(i = 0; i < MAX; i++)
        {
                num[i] = rand();
        }

        // Intercambiamos los elementos
        for(i = 1; i < MAX/2; i++)
        {
                tmp = num[i];
                num[i] = num[MAX - i - 1];
                num[MAX - i - 1] = tmp;
        }

        // Mostramos el resultado
        for(i = 0; i < MAX; i++)
        {
                cout << "num[" << i << "]=" << num[i];
        }

        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