Semana 3

Durante esta semana continuaremos explorando el lenguaje de programación C. En particular arreglos, memoria dinámica y estructuras de datos.

Material de clase

El material que vamos a trabajar esta semana en clase lo pueden encontrar en este enlace Y en este otro enlace.

Nota

¡Alerta de Spoiler!

En este enlace se encuentra la solución a algunos puntos de la primera guía y en este otro enlace la solución de algunos puntos para la segunda.

Ejercicio en clase

 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
 #include <stdio.h>
 #define MAX 100

 void printArray(int *pdata,int n){

     printf("\n The array is: \n");

     for(int i = 0; i< n ;i++) {
         printf("data[%d]: %d\n",i,  *(pdata+i) );
     }
 }

 int main(){
     int n;
     int data[MAX];
     int position;

     printf("Enter the length of the array: ");
     scanf("%d", &n);
     printf("Enter %d elements of the array \n",n);

     for(int i = 0; i < n; i++){
         scanf("%d", &data[i]);
     }
     printArray(data, n);

     printf("\n Enter the position where to insert: ");
     scanf("%d", &position);
     position--;
     for(int i = n-1;i >= position; i--){
         data[i+1] = data[i];
     }
     printf("\nEnter the value: ");
     scanf("%d", &data[position]);

     printArray(data,n+1);
     return 0;
 }