Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- typedef struct
- {
- int numer;
- char nazwa[50];
- float promien;
- }Planeta;
- Planeta func(Planeta *arr,int size)
- {
- float a;
- Planeta b;
- float *v=(float*)malloc(sizeof(float)*size);
- float pi=3.14;
- for (int i = 0; i < size; i++)
- {
- if (arr[i].numer % 2 == 0)
- {
- v[i] = (4 / 3)*pi*pow(arr[i].promien, 3);
- }
- else
- {
- v[i] = 0.9*((4 / 3)*pi*pow(arr[i].promien, 3));
- }
- }
- for (int i = 0; i < size-1; i++)
- {
- for (int j = 0; j < size-1; j++)
- {
- if(v[j]<v[j+1])
- {
- a = v[j + 1];
- v[j + 1] = v[j];
- v[j] = a;
- b = arr[j + 1];
- arr[j + 1] = arr[j];
- arr[j] = b;
- }
- }
- }
- return arr[0];
- }
- void kolos1()
- {
- Planeta arr[3];
- arr[0].numer = 1;
- strcpy(arr[0].nazwa, "Kolos wielki");
- arr[0].promien = 8000;
- arr[1].numer = 2;
- strcpy(arr[1].nazwa, "duza planeta");
- arr[1].promien = 5000;
- arr[2].numer = 3;
- strcpy(arr[2].nazwa, "lodowy gigant");
- arr[2].promien = 2000;
- Planeta temp= func(arr, 3);
- printf("%d %s %f", temp.numer, temp.nazwa, temp.promien);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement