█████████ ████ ███░░░░░███ ░░███ ███ ░░░ ██████ ███████ ██████ ██████ ░███ ███░░███ ███░░███ ███░░███ ███░░███ ░███ ░███ ░███░███ ░███ ░███████ ░███ ░███ ░░███ ███░███ ░███░███ ░███ ░███░░░ ░███ ░███ ░░█████████ ░░██████ ░░████████░░██████ ░░██████ ░░░░░░░░░ ░░░░░░ ░░░░░░░░ ░░░░░░ ░░░░░░

Envío 1127

Problema 0x62 - Contar elementos mayores a X en un arreglo pequeño

  • Autor: EduardoVega
  • Fecha: 2020-10-11 00:28:14 UTC (Hace alrededor de 4 años)
Caso # Resultado Tiempo Memoria
#1
Error de compilación
                      main.c:2:19: error: expected "FILENAME" or <FILENAME>
#include <stdlib.h
                  ^
main.c:10:16: warning: format specifies type 'long *' but the argument has type 'long' [-Wformat]
  scanf("%li", size_array);
         ~~~   ^~~~~~~~~~
main.c:11:11: warning: implicitly declaring library function 'malloc' with type 'void *(unsigned long)' [-Wimplicit-function-declaration]
  array = malloc(sizeof(long int) * size_array);
          ^
main.c:11:11: note: include the header <stdlib.h> or explicitly provide a declaration for 'malloc'
main.c:31:20: warning: format specifies type 'int' but the argument has type 'long' [-Wformat]
    printf("%d\n", contador);
            ~~     ^~~~~~~~
            %ld
main.c:35:3: warning: implicit declaration of function 'free' is invalid in C99 [-Wimplicit-function-declaration]
  free(array);
  ^
4 warnings and 1 error generated.

                    
#2
Error de compilación
                      main.c:2:19: error: expected "FILENAME" or <FILENAME>
#include <stdlib.h
                  ^
main.c:10:16: warning: format specifies type 'long *' but the argument has type 'long' [-Wformat]
  scanf("%li", size_array);
         ~~~   ^~~~~~~~~~
main.c:11:11: warning: implicitly declaring library function 'malloc' with type 'void *(unsigned long)' [-Wimplicit-function-declaration]
  array = malloc(sizeof(long int) * size_array);
          ^
main.c:11:11: note: include the header <stdlib.h> or explicitly provide a declaration for 'malloc'
main.c:31:20: warning: format specifies type 'int' but the argument has type 'long' [-Wformat]
    printf("%d\n", contador);
            ~~     ^~~~~~~~
            %ld
main.c:35:3: warning: implicit declaration of function 'free' is invalid in C99 [-Wimplicit-function-declaration]
  free(array);
  ^
4 warnings and 1 error generated.

                    
#3
Error de compilación
                      main.c:2:19: error: expected "FILENAME" or <FILENAME>
#include <stdlib.h
                  ^
main.c:10:16: warning: format specifies type 'long *' but the argument has type 'long' [-Wformat]
  scanf("%li", size_array);
         ~~~   ^~~~~~~~~~
main.c:11:11: warning: implicitly declaring library function 'malloc' with type 'void *(unsigned long)' [-Wimplicit-function-declaration]
  array = malloc(sizeof(long int) * size_array);
          ^
main.c:11:11: note: include the header <stdlib.h> or explicitly provide a declaration for 'malloc'
main.c:31:20: warning: format specifies type 'int' but the argument has type 'long' [-Wformat]
    printf("%d\n", contador);
            ~~     ^~~~~~~~
            %ld
main.c:35:3: warning: implicit declaration of function 'free' is invalid in C99 [-Wimplicit-function-declaration]
  free(array);
  ^
4 warnings and 1 error generated.

                    
#4
Error de compilación
                      main.c:2:19: error: expected "FILENAME" or <FILENAME>
#include <stdlib.h
                  ^
main.c:10:16: warning: format specifies type 'long *' but the argument has type 'long' [-Wformat]
  scanf("%li", size_array);
         ~~~   ^~~~~~~~~~
main.c:11:11: warning: implicitly declaring library function 'malloc' with type 'void *(unsigned long)' [-Wimplicit-function-declaration]
  array = malloc(sizeof(long int) * size_array);
          ^
main.c:11:11: note: include the header <stdlib.h> or explicitly provide a declaration for 'malloc'
main.c:31:20: warning: format specifies type 'int' but the argument has type 'long' [-Wformat]
    printf("%d\n", contador);
            ~~     ^~~~~~~~
            %ld
main.c:35:3: warning: implicit declaration of function 'free' is invalid in C99 [-Wimplicit-function-declaration]
  free(array);
  ^
4 warnings and 1 error generated.

                    
#5
Error de compilación
                      main.c:2:19: error: expected "FILENAME" or <FILENAME>
#include <stdlib.h
                  ^
main.c:10:16: warning: format specifies type 'long *' but the argument has type 'long' [-Wformat]
  scanf("%li", size_array);
         ~~~   ^~~~~~~~~~
main.c:11:11: warning: implicitly declaring library function 'malloc' with type 'void *(unsigned long)' [-Wimplicit-function-declaration]
  array = malloc(sizeof(long int) * size_array);
          ^
main.c:11:11: note: include the header <stdlib.h> or explicitly provide a declaration for 'malloc'
main.c:31:20: warning: format specifies type 'int' but the argument has type 'long' [-Wformat]
    printf("%d\n", contador);
            ~~     ^~~~~~~~
            %ld
main.c:35:3: warning: implicit declaration of function 'free' is invalid in C99 [-Wimplicit-function-declaration]
  free(array);
  ^
4 warnings and 1 error generated.

                    
#6
Error de compilación
                      main.c:2:19: error: expected "FILENAME" or <FILENAME>
#include <stdlib.h
                  ^
main.c:10:16: warning: format specifies type 'long *' but the argument has type 'long' [-Wformat]
  scanf("%li", size_array);
         ~~~   ^~~~~~~~~~
main.c:11:11: warning: implicitly declaring library function 'malloc' with type 'void *(unsigned long)' [-Wimplicit-function-declaration]
  array = malloc(sizeof(long int) * size_array);
          ^
main.c:11:11: note: include the header <stdlib.h> or explicitly provide a declaration for 'malloc'
main.c:31:20: warning: format specifies type 'int' but the argument has type 'long' [-Wformat]
    printf("%d\n", contador);
            ~~     ^~~~~~~~
            %ld
main.c:35:3: warning: implicit declaration of function 'free' is invalid in C99 [-Wimplicit-function-declaration]
  free(array);
  ^
4 warnings and 1 error generated.

                    
#7
Error de compilación
                      main.c:2:19: error: expected "FILENAME" or <FILENAME>
#include <stdlib.h
                  ^
main.c:10:16: warning: format specifies type 'long *' but the argument has type 'long' [-Wformat]
  scanf("%li", size_array);
         ~~~   ^~~~~~~~~~
main.c:11:11: warning: implicitly declaring library function 'malloc' with type 'void *(unsigned long)' [-Wimplicit-function-declaration]
  array = malloc(sizeof(long int) * size_array);
          ^
main.c:11:11: note: include the header <stdlib.h> or explicitly provide a declaration for 'malloc'
main.c:31:20: warning: format specifies type 'int' but the argument has type 'long' [-Wformat]
    printf("%d\n", contador);
            ~~     ^~~~~~~~
            %ld
main.c:35:3: warning: implicit declaration of function 'free' is invalid in C99 [-Wimplicit-function-declaration]
  free(array);
  ^
4 warnings and 1 error generated.

                    
#8
Error de compilación
                      main.c:2:19: error: expected "FILENAME" or <FILENAME>
#include <stdlib.h
                  ^
main.c:10:16: warning: format specifies type 'long *' but the argument has type 'long' [-Wformat]
  scanf("%li", size_array);
         ~~~   ^~~~~~~~~~
main.c:11:11: warning: implicitly declaring library function 'malloc' with type 'void *(unsigned long)' [-Wimplicit-function-declaration]
  array = malloc(sizeof(long int) * size_array);
          ^
main.c:11:11: note: include the header <stdlib.h> or explicitly provide a declaration for 'malloc'
main.c:31:20: warning: format specifies type 'int' but the argument has type 'long' [-Wformat]
    printf("%d\n", contador);
            ~~     ^~~~~~~~
            %ld
main.c:35:3: warning: implicit declaration of function 'free' is invalid in C99 [-Wimplicit-function-declaration]
  free(array);
  ^
4 warnings and 1 error generated.

                    
#9
Error de compilación
                      main.c:2:19: error: expected "FILENAME" or <FILENAME>
#include <stdlib.h
                  ^
main.c:10:16: warning: format specifies type 'long *' but the argument has type 'long' [-Wformat]
  scanf("%li", size_array);
         ~~~   ^~~~~~~~~~
main.c:11:11: warning: implicitly declaring library function 'malloc' with type 'void *(unsigned long)' [-Wimplicit-function-declaration]
  array = malloc(sizeof(long int) * size_array);
          ^
main.c:11:11: note: include the header <stdlib.h> or explicitly provide a declaration for 'malloc'
main.c:31:20: warning: format specifies type 'int' but the argument has type 'long' [-Wformat]
    printf("%d\n", contador);
            ~~     ^~~~~~~~
            %ld
main.c:35:3: warning: implicit declaration of function 'free' is invalid in C99 [-Wimplicit-function-declaration]
  free(array);
  ^
4 warnings and 1 error generated.

                    
#10
Error de compilación
                      main.c:2:19: error: expected "FILENAME" or <FILENAME>
#include <stdlib.h
                  ^
main.c:10:16: warning: format specifies type 'long *' but the argument has type 'long' [-Wformat]
  scanf("%li", size_array);
         ~~~   ^~~~~~~~~~
main.c:11:11: warning: implicitly declaring library function 'malloc' with type 'void *(unsigned long)' [-Wimplicit-function-declaration]
  array = malloc(sizeof(long int) * size_array);
          ^
main.c:11:11: note: include the header <stdlib.h> or explicitly provide a declaration for 'malloc'
main.c:31:20: warning: format specifies type 'int' but the argument has type 'long' [-Wformat]
    printf("%d\n", contador);
            ~~     ^~~~~~~~
            %ld
main.c:35:3: warning: implicit declaration of function 'free' is invalid in C99 [-Wimplicit-function-declaration]
  free(array);
  ^
4 warnings and 1 error generated.

                    
Puntos totales: 0 / 100

Código

#include <stdio.h>
#include <stdlib.h

int main()
{
  long int size_array = 0, num_consultas = 0, 
  num_arr = 0, contador = 0, consulta = 0, i, j;
  long int *array = NULL;  

  scanf("%li", size_array);
  array = malloc(sizeof(long int) * size_array);
  if (array == NULL || size_array <= 0)
      return -1;

  for (i = 0; i < size_array; i++)
  {
     scanf("%li", &num_arr);
     array[i] = num_arr; 
  }

  scanf("%li", &num_consultas);

  for (i = 0; i < num_consultas; i++)
  {
    scanf("%li", &consulta);
    for (j = 0; j < size_array; j++)
    {
      if (array[j] > consulta)
          contador++;
    }
    printf("%d\n", contador);
    contador = 0;
  }
  
  free(array);
  return 0;  
}