typedef struct point Point; struct point { double x; double y; };
double distA( double p[2], double q[2] ); double distS( Point p, Point q );Recall that the formula for the distance between 2 points is
distance = sqrt ((x2-x1)^2 + (y2-y1)^2)
Do you find one version of the function "easier to read" than the other?
It should have the following prototype
int readPoints(Point points[], int maxPoints);
(4.5,9.0)
#define MAX_PLATE typedef struct parkingFine ParkingFine; struct parkingFine{ double amount; char numberPlate[MAX_PLATE]; }; int readParkingFine ( ParkingFine fine ); int main(void){ ParkingFine f; if(readParkingFine(f)){ printf("%lf %s\n",f.amount, f.numberPlate); } else { fprintf(stderr,"Invalid Input\n"); return EXIT_FAILURE; } return EXIT_SUCCESS; } // Returns 1 if valid input was read in // Returns 0 otherwise int readParkingFine ( ParkingFine fine ){ if ( scanf("%lf",&fine.amount) != 1 || fgets(fine.numberPlate,MAX_PLATE,stdin) == NULL){ return 0; } else { return 1; } }
#define MAX_LEN 100 typedef struct student Student; struct student{ int zid; char name[MAX_LEN]; }Write a function to return a pointer to a Student with the given zid from an array of Student. It should return NULL otherwise. Your function should have the following prototype
Student * findStudent(Student class[], int size, int zid);