Dev - C++ - Ejercicios con arreglos

 
Vista:

Ejercicios con arreglos

Publicado por jorge moody (4 intervenciones) el 05/12/2019 04:14:28
1.- Escriba un programa que acepte un arreglo, imprima los datos tal y como fueron ingresados y luego en orden inverso.

2.- Escriba un programa que acepte dos arreglos unidimensionales, los sume y el resultado debe almacenarse en un tercer arreglo. (A=B+C).

3.- Escriba un programa que cuente la cantidad de elementos positivos de un arreglo e imprima dicho valor.
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
-1
Responder
Imágen de perfil de Alfil
Val: 4.344
Oro
Ha mantenido su posición en Dev - C++ (en relación al último mes)
Gráfica de Dev - C++

ayuda porfaEjercicios con arreglos

Publicado por Alfil (1444 intervenciones) el 05/12/2019 09:17:56
1.-

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <iostream>
 
using namespace std;
 
int main()
{
    int sz;
 
    cout << "\nTamanio del arreglo: ";
    cin >> sz;
 
    int arreglo[sz];
 
    cout << "\nDatos del arreglo:\n";
    for( int i = 0; i < sz; i++ ) {
        cout << "(" << i + 1 << "/" << sz << "): ";
        cin >> arreglo[i];
    }
 
    cout << "\nArreglo: ";
    for( int i = 0; i < sz; i++ )
        cout << arreglo[i] << " ";
 
    cout << "\n\nArreglo inverso: ";
    for( int i = sz - 1; i >= 0; i-- )
        cout << arreglo[i] << " ";
 
    cout << endl;
 
    return 0;
}

2.-

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <iostream>
 
using namespace std;
 
int main()
{
    int sz;
 
    cout << "\nTamanio del arreglo: ";
    cin >> sz;
 
    int a[sz];
    int b[sz];
    int c[sz] = { 0 };
 
    cout << "\nDatos del arreglo 1:\n";
    for( int i = 0; i < sz; i++ ) {
        cout << "(" << i + 1 << "/" << sz << "): ";
        cin >> a[i];
    }
 
    cout << "\nDatos del arreglo 2:\n";
    for( int i = 0; i < sz; i++ ) {
        cout << "(" << i + 1 << "/" << sz << "): ";
        cin >> b[i];
    }
 
    for( int i = 0; i < sz; i++ ) {
        c[i] = a[i] + b[i];
    }
 
    cout << "\nLa suma es: ";
    for( int i = 0; i < sz; i++ )
        cout << c[i] << " ";
 
 
 
    cout << endl;
 
    return 0;
}

3.-

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>
 
using namespace std;
 
int main()
{
    int sz, pos = 0;
 
    cout << "\nTamanio del arreglo: ";
    cin >> sz;
 
    int a[sz];
 
    cout << "\nDatos del arreglo:\n";
    for( int i = 0; i < sz; i++ ) {
        cout << "(" << i + 1 << "/" << sz << "): ";
        cin >> a[i];
        if( a[i] > 0 ) pos++;
    }
 
    cout << "\nEl arreglo tiene " << pos << " numeros positivos" << endl;
 
    return 0;
}
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar