Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <stdio.h>
- #include <time.h>
- #include<math.h>
- struct punkt
- {
- double x,y,z;
- };
- void wypisz( struct punkt t[],int x)
- {
- int i;
- for(i=0;i<x;i++)
- {
- printf("Punkt ");
- printf("%d", i+1);
- printf(": ");
- printf("%lf", t[i].x);
- printf(", ");
- printf("%lf", t[i].y);
- printf(", ");
- printf("%lf", t[i].z);
- printf(", ");
- printf("\n");
- }
- }
- void wypelnijrecznie( struct punkt tab[], int i)
- {
- int x;
- printf("Wypelnij tablice swoimi danymi: \n");
- for(x=0;x<i;x++)
- {
- printf("Kolejny punkt\n");
- printf("X: ");
- scanf("%lf", &tab[x].x);
- printf("Y: ");
- scanf("%lf", &tab[x].y);
- printf("Z: ");
- scanf("%lf", &tab[x].z);
- }
- }
- void wypelnijlosowo( struct punkt tab[], int i)
- {
- int x;
- for(x=0;x<=i;x++)
- {
- tab[x].x=((rand() % 10) + 0)+0.1*(rand() % 10)+0.01*(rand() % 10)+0.001*(rand() % 10)+0.0001*(rand() % 10)+0.00001*(rand() % 10)+0.000001*(rand() % 10);
- tab[x].y=((rand() % 10) + 0)+0.1*(rand() % 10)+0.01*(rand() % 10)+0.001*(rand() % 10)+0.0001*(rand() % 10)+0.00001*(rand() % 10)+0.000001*(rand() % 10);
- tab[x].z=((rand() % 10) + 0)+0.1*(rand() % 10)+0.01*(rand() % 10)+0.001*(rand() % 10)+0.0001*(rand() % 10)+0.00001*(rand() % 10)+0.000001*(rand() % 10);
- }
- }
- void odleglosc2pkt()
- {
- double x,y,z,x1,y1,z1,odl;
- printf("Punkt 1:\n");
- printf("X: ");
- scanf("%lf", &x);
- printf("Y: ");
- scanf("%lf", &y);
- printf("Z: ");
- scanf("%lf", &z);
- printf("Punkt 2:\n");
- printf("X: ");
- scanf("%lf", &x1);
- printf("Y: ");
- scanf("%lf", &y1);
- printf("Z: ");
- scanf("%lf", &z1);
- odl=sqrt(pow(x1-x,2) + pow(y1-y,2) + pow(z1-z,2));
- printf("Odleglosc miedzy podanymi punktami to: ");
- printf("%lf", odl);
- printf("\n");
- }
- void sortowanie(struct punkt tab[], int i)
- {
- int a,b=0,c;
- double max,akt,pom;
- for(b=0;b<i;b++)
- {
- max=sqrt(pow(tab[b].x,2) + pow(tab[b].y,2) + pow(tab[b].z,2));
- for(a=0;a<=i;a++)
- {
- akt=sqrt(pow(tab[a].x,2) + pow(tab[a].y,2) + pow(tab[a].z,2));
- if(akt>max)
- {
- max=akt;
- c=a;
- }
- }
- if((c=!b))
- {
- pom=tab[c].x;
- tab[b].x=tab[c].x;
- tab[b].x=pom;
- pom=tab[c].y;
- tab[b].y=tab[c].y;
- tab[b].y=pom;
- pom=tab[c].z;
- tab[b].z=tab[c].z;
- tab[b].z=pom;
- }
- }
- }
- void dodaj(struct punkt *tab, int rozm)
- {
- tab =(struct punkt*) realloc(tab, (rozm+1)*sizeof(struct punkt));
- }
- int main()
- {
- srand(time(NULL));
- int size,a;
- printf("Jakiej wielkosci tablice chcesz stworzyc? \n");
- scanf("%d", &size);
- struct punkt * tablica = malloc(size*sizeof(struct punkt));
- while (1)
- {
- printf("'1' - Wypelnij zadana tablice punktow wartosciami podanymi przez uzytkownika\n");
- printf("'2' - Wypelnij zadana tablice punktow losowymi wartosciami [0.00;10.00]\n");
- printf("'3' - Wyznaczanie odleglosci miedzy dwoma punktami podanymi przez uzytkownika\n");
- printf("'4' - Sortuje zadana tablice wedlug odleglosci punktow od punktu (0,0,0)\n");
- printf("'5' - Dodaj element na koniec tablicy\n");
- printf("'6' - Usuwa pierwszy element tablicy\n");
- printf("'7' - Dodaje element na podane miejsce w tablicy\n");
- printf("'8' - Wyswietl tablice na ekranie\n");
- printf("'0' - Zakoncz dzialanie programu\n");
- printf("Podaj opcje, ktora chcesz wykonac: ");
- scanf("%d", &a);
- switch (a)
- {
- case 0:
- printf("\n");
- printf("Wylaczam sie! Milego Dnia!");
- exit(0);
- case 1:
- wypelnijrecznie(tablica,size);
- break;
- case 2:
- wypelnijlosowo(tablica,size);
- break;
- case 3:
- odleglosc2pkt();
- break;
- case 4:
- sortowanie(tablica,size);
- break;
- case 5:
- dodaj(tablica,size++);
- break;
- case 6:
- break;
- case 7:
- break;
- case 8:
- wypisz(tablica, size);
- break;
- default: printf("Nie ma takiego polecenia do wyboru\n");
- }
- }
- free(tablica);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement