So basically I need to make an array (hlp) which would include the m amount of highest numbers out of a scanned array (pole).
My code should be correct but doesn't work (it ignores the first numbers in the original array)
Please help me find the issue
Code:
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[]) {
int i, m, n, x, j, l, o;
int k, r, h, z;
int pole[n];
int hlp[m];
printf("Input m\n");
scanf("%d", &m);
printf("Input n\n");
scanf("%d", &n);
while(m>n||m>200||m<1||n<1)
{
printf("Error\n");
printf("Input m\n");
scanf("%d", &m);
printf("Input n\n");
scanf("%d", &n);
}
for(r=0; r<m;r++)
{
hlp[r]=0;
}
printf("Input array\n");
for(i=0; i<n; i++)
{
scanf("%d", &o);
pole[i]=o;
}
for(i=0; i<n; i++)
{
j=0;
while(pole[i]<hlp[j] && j<m)
{
j=j+1;
}
if(pole[i]>hlp[j])
{
for(l=m; l>j; l--)
{
hlp[l]=hlp[l-1];
}
}
hlp[j]=pole[i]
}
for(i=0; i<m; i++)
{
printf("%d, ", hlp[i]);
}
return 0;
}