I just started to learn pointers, so I'm interested if I used them correctly in this task where I check if the absolute value of the greatest element in an array is two times greater than the absolute value of the smallest one.
My code works properly; I'm just interested if I used the pointer correctly (it should only be used for an array).
#include <stdio.h>
#include<math.h>
int minmax2x(float* array, int size){
double min=array[0],max=array[0];
int i;
for(i=0;i<size;i++){
if(array[i]<0)
array[i]=array[i]*(-1);
}
for(i=0;i<size;i++){
if(array[i]>max)
max=array[i];
if(array[i]<min)
min=array[i];
}
if(max>2*min)
return 1;
else return 0;
}
int main() {
float array1[5] = { 5.5, 6.6, -7.7, -6.6, -5.5};
float array2[5] = { 3.3, 2.2, 1.1, 2.2, 3.3};
int res1 = minmax2x(array1, 5);
int res2 = minmax2x(array2, 5);
printf("%d %d", res1, res2);
}