Coder Social home page Coder Social logo

https-github.com-optativopucv-2022_1-lab1-davor2003's Introduction

Ejercicios sobre punteros arreglos y la declaración Struct


Antes de comenzar

  • Abra el Visual Studio Code y abra una nueva ventana
  • En el explorador ponga la opción para clonar repositorio y clone este repositorio
  • Sólo puede modificar el archivo exercises.c
  • Para testear sus códigos debe abrir un terminal git bash y ejecutar el comando ./test.sh
  • Verifique que sus cambios se hayan subido al repositorio en github
  • No está permitido usar comandos de git (a menos que el profesor lo indique)

  1. Escriba el código para la función void suma(int a, int b, int * c), la cual recibe 3 parámetros (a, b y c), y en c almacena el valor de la suma de a más b.

  2. Considere la siguiente función:

int sumaN(int a[], int N) { // Suma N números del arreglo.
    int i;
    int tot = 0;

    for(i = 0; i < N; i++) {
      tot += a[i];
    }

    return tot;
}

Programe la función void sumaNultimos(int a[], int n, int m, int *suma). Esta función suma los últimos m números del arreglo a y almacena el resultado en *suma. El arreglo a es una arreglo de n enteros (n>m).

Debe hacer uso de la función int sumaN(int a[], int N)

(Sugerencia: recuerde la relación existente entre arreglos y punteros).

  1. Considere la siguiente struct Persona:
typedef struct {
  char nombre[30];
  char rut[11];
  int edad;
} Persona; 

Programe la función Persona *crearPersona(...), la cual crea una nueva persona con los datos correspondientes y retorna un puntero al dato recién creado.

  1. Considere la siguiente struct Vector:
typedef struct {
   int * datos; // arreglo dinámico
   int capacidad; // capacidad del arreglo
} Vector;

Escriba la función Vector* crearVector(int n), la cual crea un vector con capacidad n, reserva la memoria correspondiente para el arreglo con n datos inicializados en 0 y luego retorna el vector creado.

  1. Programe las función void asignarValor(Vector * v, int i, int valor), la cual asigna valor a la posición i del vector v.

  2. Programe la función int obtenerDato(Vector * v, int i), la cual retorna el dato en la posición i del vector v.

  3. Programe la función void sumaV(Vector * a, Vector * b, Vector * c), la cual suma los vectores a y b y actualiza el vector c con el resultado de la suma. Asuma que los vecotres tienen el mismo tamaño.

Por ejemplo, si:

a: [0 4  8 12 16 20 24 28 32 36]
b: [0 8 16 24 32 40 48 56 64 72]

, entonces:

c: [0 12 24 36 48 60 72 84 96 108 ]
  1. Implemente la función sumaV2(int a1, int a2, int b1, int b2, Vector *c). Esta función realiza la suma de vectores (a1,a2)+(b1,b2) y almacena el resultado en el vector c. Utilice las operaciones de vectores implementadas anteriormente!

https-github.com-optativopucv-2022_1-lab1-davor2003's People

Contributors

davor2003 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.