hi!
I am having trouble with this private project of mine. I am not much of a programmer, so i am stuck now with my equations but am not
able to complete my code... would be greatful for help!I have started the code by lookin into books, sites, etc, but it is far from over
I have 4 sensors giving me values & they are saved in a table along with the "serial number" & a parameter- distance ( d )
Nr d S1 S2 S3 S4
1 0.5 2000 2102 2000 2333
2 1 2100 2234 2200 2400
3 1.5 2230 2299 2300 2500
4 2 2290 2402 2400 2600
5 2.5 2400 2499 2400 2700
.
.
.
100
Now in the first step i want to find from the 100 readings the 5 most suitable, for that i find the "smallest distance"
with
a[i] = sqrt( ( s(i)1 -s11) * (s(i)1 - s11 ) + (s(i)2 - s12 )*( s(i)2 - s12 ) + (s(i)3 - s13) * (s(i)3-s13) + ( s(i)4 - s14 ) * ( s(i)4 - s14 ) );
Where i is the number of the reading, the number which increases ... 1,2,3,4 are the sensors 1-4
after this i need to sort the a[i] & pick out the five with the smallest distance.
with the five sets ( with the d, s1, s2 , s3 & s4 )i have to do further calcultaions. Nut will be greatful for help till here :-)
attached is the code i have tried till here.
Regards!
Code:int a[100] for ( i=0;i<n;i++) { a[i] = sqrt( ( s(i)1 -s11) * (s(i)1 - s11 ) + (s(i)2 - s12 )*( s(i)2 - s12 ) + (s(i)3 - s13) * (s(i)3-s13) + ( s(i)4 - s14 ) * ( s(i)4 - s14 ) ); } int x,n,i,j; for(i=0;i<n;i++) { scanf("%d",&a[i]); } for(i=0;i<100;i++) { for(j=0;j<n-1;j++) if(a[j]>a[j+1]) { x=a[j]; a[j]=a[j+1]; a[j+1]=x; } } printf("array in ascending order\n"); for(i=0;i<n;i++) { printf("%d\n",a[i]); } printf (" smallest distances : %d %d %d %d %d",a[1],a[2],a[3],a[4],a[5]);



LinkBack URL
About LinkBacks






