Please write the program in C not C++ or C# In this exercise you will build a sm
ID: 3722213 • Letter: P
Question
Please write the program in C not C++ or C#
In this exercise you will build a small library of utility functions by implementing the following functions with the given prototypes and specified functionality · int degreesToRadians (double degree, double *radians) -write a function to convert degrees to radians using the formula 180 The function should place the computed value into the radians variable, which is passed by reference. The return value should indicate an error code: 0 for no error, 1 for any type of error NULL pointers, or an invalid degree which should be on the scale [0, 360 int compute the annual percentage yield given an annual percentage rate using the fol- lowing formula annualPercentageYield(double double *apy) -this function should · apr, variable, which is The function should place the computed value into the apy passed by reference. The return value should indicate an error code: 0 for no error, 1 for any type of error (NULL pointers, or an invalid APR which should be on the scale [0, 1] . int getAirDistance (double latA, double longA, double latB, double longB, double *distance) this function should compute the air distance between the two locations given by their latitude/longitude. The latitude and longitude are on the scale -180, 180] (negative values are southern and western hemisphere). The air distance between two latitude/longitude points can be calculated with the Spherical Law of Cosines d = arccos (sin(A ) sin(P2) + cos(A) cos(p) cos(A) ) . R where -p 1 is the latitude of location A, P2 is the latitude of location B is the difference between location B's longitude and location A's longitude - R is the (average) radius of the earth, 6,371 kilometersExplanation / Answer
int degreesToRadians(double degree, double *radians){
if (radians == NULL || degree < 0 || degree > 360){
return 0;
}
*radians = (degree * M_PI)/180;
return 1;
}
int annualPercentageYield(double apr, double *apy){
if (apy == NULL || apr < 0 || apr > 1){
return 0;
}
*apy = exp(apr) - 1;
return 1;
}
int getAirDistance(double latA, double longA,
double latB, double longB, double *distance){
if (distance == NULL || latA < -90 || latA > 90
|| longA < -180 || longA > 180 || latB < -90 || latB > 90
longB < -180 || longA > 180){
return 0;
}
double radlatA = (latA * M_PI)/180;
double radlatB = (latB * M_PI)/180;
double radlongA = (longA * M_PI)/180;
double radlongB = (longB * M_PI)/180;
double delta = radlongA - radlongB;
double R = 6371;
*distance = acos(sin(radlatA)*sin(radlatB) + cos(radlatA)*cos(radlatB)*cos(delta))*R
return 1;
}
double maxd(double a, double b, double c){
if (a > b){
if (a > c)
return a;
else
return c;
}
else {
if (b > c)
return b;
else
return c;
}
}
int rgbToCMYK(int r, int g, int b, double *c, double *m, double *y, double *k){
if (c == NULL || m == NULL || y == NULL || k == NULL || r < 0 || r >255
|| g < 0 || g > 255 || g < 0 || g > 255){
return 0;
}
double r1 = r/255;
double g1 = g/255;
double b1 = b/255;
*k = 1 - maxd(r1,g1,b1);
*c = (1-r1-*k)/(1-*k);
*m = (1-g1-*k)/(1-*k);
*y = (1-b1-*k)/(1-*k);
return 1;
}
int cmykToRGB(double c, double m, double y, double k,int *r, int *g, int *b, ){
if (r == NULL || g == NULL || b == NULL || c < 0 || c > 1
|| m < 0 || m > 1 || y < 0 || y > 1 || k < 0 || k > 1){
return 0;
}
*r = 255 * (1-*c) * (1-*k);
*g = 255 * (1-*m) * (1-*k);
*b = 255 * (1-*y) * (1-*k);
return 1;
}
int maxI(int a, int b, int c){
if (a > b){
if (a > c)
return a;
else
return c;
}
else {
if (b > c)
return b;
else
return c;
}
}
int minI(int a, int b, int c){
if (a < b){
if (a < c)
return a;
else
return c;
}
else {
if (b < c)
return b;
else
return c;
}
}
int toGrayScale(int *r, int *g, int *b, Mode m){
double res;
if (r == NULL || g || NULL || b == NULL || m != AVERAGE || m != LIGHTNESS
|| m != LUMINOSITY){
return 0;
}
if (m == AVERAGE){
res = (*r + *g + *b)/3;
}
if (m == LIGHTNESS){
res = maxI(*r,*g,*b) + minI(*r,*g,*b))/2;
}
if (m == LUMINOSITY){
res = 0.21 * (*r) + 0.72* (*g) + 0.07 * (*b);
}
return res;
}