I'm trying to learn recursion and am in doubt on an issue I was doing in c, I need to add how many numbers of a vector with n elements are larger than a number x. This recursion simply does not go into the head, I need a clearing.
#include <stdio.h>
#include <stdlib.h>
int busca(int v[], int n, int k)
{
int x = 0;
if(n == 1)
{
if( k < v[0])
x= x + 1;
}
else
{
if(k < v[n])
x = x+ 1;
busca( v, n-1 ,k);
}
return x;
}
int main()
{
int n, k,x;
printf("DIGITE A QUANTIDADE DE ELEMENTOS DO VETOR:");
scanf("%d", &n);
int v[n];
int i;
for(i = 1; i <= n; i++)
{
printf("Digite o elemento %d: ", i);
scanf("%d", &v[i]);
}
printf("Digite um numero: ");
scanf("%d", &k);
//printf ("%d",
printf("x = %d", busca(v, n, k));
return 0;
}