Code:
#include <stdio.h>
#include <math.h>
int myfunction(int,float[],int);
int main(void){
float oranges[3];
float selection;
int apples=1000;
int i;
float pears;
float select;
for(i=0;i<=apples;i=i+10){
pears=sqrt(pow((i-oranges[myfunction(i,oranges,apples)]),2));
printf("%f ",pears);
/*if(pears>30.0){
selection=5.0;
}
if(pears<=30.0){
selection=10.0;
}*/
}
while(0==0){}
}
int myfunction(int position,float oranges[],int apples){
int returnvar;
float pears=apples+1;
int i;
for(i=1;i<=3;i++){
if(sqrt((oranges[i]-position)*(oranges[i]-position))<pears){
pears=sqrt((oranges[i]-position)*(oranges[i]-position));
returnvar=i;
}
}
return returnvar;
}
For starters, I don't like the way I'm squaring the value then square rooting it to make any negatives positive (i.e |Modulus| in the world of Maths). Is there a function in C that will allow me to do this?
Thanks for you help,
T