#include <stdio.h>
#include <stdlib.h>

typedef struct {
  double x;
  double y;
  double z;
} Pt3D;

Pt3D Diff( Pt3D p1, Pt3D p2) {
  Pt3D tmp;

  tmp.x = p1.x - p2.x;
  tmp.y = p1.y - p2.y;
  tmp.z = p1.z - p2.z;
 
  return tmp;
}

void Prob4(void) {
  Pt3D p1, p2, p3;
  p1.x = 4;
  p1.y = 5;
  p1.z = 1;
  p2.x = 5;
  p2.y = 3;
  p2.z = 2;
  p3 = Diff(p1, p2);

  printf("diff of p1 and p2 is %g %g %g\n", p3.x, p3.y, p3.z);
}

/*********************************************/
int FindMax(double nums[], int start, int end) {
  int i, indx;
  indx = start;
  for (i=start; i<end; i++) {
    if (nums[i] > nums[indx]) {
     indx = i;
    }
  }
  return indx;
}

void Swap(double nums[], int l, int r) {
  double tmp;
  tmp = nums[l];
  nums[l] = nums[r];
  nums[r] = tmp;
}

void SelectSort(double nums[], int size) {
  int l, r;

  for (l=0; l<size; l++) {
    r = FindMax(nums, l, size);
    Swap(nums, l, r);
  }
}
/*********************************************/

int cel2fah(int c);
void loop() ;

int main(void) {

  int i;
  double numbers[] = { -2.1, -2.0, 3.1, 3.0, -1.7};

  /*problem #1*/
  printf("problem #1\n");
  loop();

  /*problem #2 */
  printf("\nproblem 2\n");
  SelectSort(numbers, 5);
  for (i=0; i < 5; i++) {
    printf("%f ", numbers[i]);
  }
  printf("\n"); 

  /*problem #4 */
  printf("\nproblem 4\n");
  Prob4();

  exit(0);
}

int cel2fah(int c) {
  return( (9/5.0)*c + 32.0 + 0.5);
}

void loop() {
  int i;
  for (i=11; i < 122; i+=11) {
    printf("%d Cel is %d Fahrenheit\n", i, cel2fah(i));
  }
}