I am trying to count the number of elements greater than the element on the right side of the array. Here my function goes.
int* SurpassersKing(int input1_size, int* input1,int* output_size)
{
int i,k;
int count[input1_size];
for (i = 0; i < input1_size; i++)
count[i] = 0;
for ( i = 0; i < input1_size; i++)
{
for ( k = i + 1; k <input1_size; k++)
{
if (input1[i] < input1[k]) {
count[i]++;
}
}
}
return count;
}
This is my function where I am counting greater elements in an array.
So in this following code snippet i have wriiten the main function , declaring all the veriable like output_size,counting array ,i ,k as an index for the arrays and printing the stuff , and calling counting function .
int main() {
int output_size;
int* output;
int ip1_size = 0;
int ip1_i;
scanf("%d\n", &ip1_size);
int ip1[ip1_size];
for(ip1_i = 0; ip1_i < ip1_size; ip1_i++) {
int ip1_item;
scanf("%d", &ip1_item);
ip1[ip1_i] = ip1_item;
}
output = SurpassersKing(ip1_size,ip1,&output_size);
int output_i;
for(output_i=0; output_i < output_size; output_i++) {
printf("%d\n", output[output_i]);
}
return 0;
}
but i am not getting the output required so what can i do to improve this.