[c] Σημεία σε κύβο 1x1
Viewer
*** This page was generated with the meta tag "noindex, nofollow". This happened because you selected this option before saving or the system detected it as spam. This means that this page will never get into the search engines and the search bot will not crawl it. There is nothing to worry about, you can still share it with anyone.
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- #include <time.h>
- struct point {
- double x;
- double y;
- double z;
- };
- struct point input(){
- struct point p;
- p.x = (double)rand() / (double) RAND_MAX;
- p.y = (double)rand() / (double) RAND_MAX;
- p.z = (double)rand() / (double) RAND_MAX;
- return p;
- }
- double dist(struct point p1, struct point p2){
- double d;
- d = sqrt(pow(p1.x-p2.x,2)+pow(p1.y-p2.y,2)+pow(p1.z-p2.z,2));
- return d;
- }
- int main(){
- srand(time(0));
- int n, i, j,c1,c2,tests,i1,i2,i3,j1,j2,j3,k;
- double max, s, mv, disTemp, firstMax, finalMax, firstMv, finalMv, difmax,amax,bmax,difmv,amv,bmv;
- printf("Give number of points: ");
- scanf("%d",&n);
- struct point cube[n];
- printf("Give number of tests: ");
- scanf("%d",&tests);
- double maxMatr[tests], mvMatr[tests];
- for (k =0; k<tests;k++){
- for (i = 0; i < n; i++)
- {
- cube[i] = input();
- }
- max = dist(cube[0],cube [0]);
- s = 0;
- c1 =0;
- c2 = 0;
- for (i=0; i<n;i++){
- for (j=0; j<n;j++){
- disTemp = dist(cube[i],cube[j]);
- s = s+ disTemp;
- if (disTemp>max)
- {
- max = disTemp;
- c1 = i;
- c2 = j;
- }
- }
- }
- mv = s/n;
- maxMatr[k] = max;
- mvMatr[k] = mv;
- }
- firstMax = maxMatr[0];
- finalMax = maxMatr[0];
- firstMv = mvMatr[0];
- finalMv = mvMatr[0];
- for (i=0;i<tests;i++){
- if (maxMatr[i]<firstMax){
- firstMax = maxMatr[i];
- }
- else if (maxMatr[i]>finalMax){
- finalMax = maxMatr[i];
- }
- if (mvMatr[i]<firstMv){
- firstMv = mvMatr[i];
- }
- else if (mvMatr[i]>finalMv){
- finalMv = mvMatr[i];
- }
- }
- difmax = finalMax-firstMax;
- amax = firstMax+difmax/3;
- bmax = finalMax-difmax/3;
- difmv = finalMv-firstMv;
- amv = firstMv+difmv/3;
- bmv = finalMv-difmv/3;
- i1=0;
- i2=0;
- i3=0;
- j1=0;
- j2=0;
- j3=0;
- for (k=0;k<tests;k++){
- if (maxMatr[k]<amax){
- i1 =i1+1;
- }
- else if (maxMatr[k]<bmax){
- i2 = i2+1;
- }
- else {
- i3 = i3+1;
- }
- if (mvMatr[k]<amv){
- j1 =j1+1;
- }
- else if (mvMatr[k]<bmv){
- j2 = j2+1;
- }
- else {
- j3 = j3+1;
- }
- }
- printf("Maximum______\n");
- printf("In [%lf,%lf]:%d \n",firstMax,amax,i1);
- printf("In [%lf,%lf]:%d \n",amax,bmax,i2);
- printf("In [%lf,%lf]:%d \n",bmax,finalMax,i3);
- printf("Mean value_______\n");
- printf("In [%lf,%lf]:%d \n",firstMv,amv,j1);
- printf("In [%lf,%lf]:%d \n",amv,bmv,j2);
- printf("In [%lf,%lf]:%d \n",bmv,finalMv,j3);
- }
Editor
You can edit this paste and save as new: