/* Rodney Biggs COP3223 Summer 2005 */ /* prg1.c 05.31.05 */ /* 1a) Distance between two points */ /* 1b) Trigonometric Functions of an angle */ #include #include #define PI = 3.14159 int choice; /* Declares choice as an integer variable */ /* The following lines ask the user to select from two choices. */ /* The program then calls the appropriate function based on the */ /* users input. */ int main(void) { printf("\nPlease choose an option:\n"); printf("\n1) Calculate the distance between two points in a plane\n"); printf("2) Calculate the trigonometric function of an angle\n"); scanf("%d", &choice); if (choice == 1) { root(); } else { trig(); } return 0; } /* The following function will calculate the distance between two points. */ int root(void) { float x1, y1, x2, y2, distance; /* Defines variables as type float */ /* The following lines of code request the user to input 2 pairs of */ /* numbers. Those numbers are then printed onto the screen in paranthesis. */ /* The numbers are then ran through the distance formula to determine the */ /* distance between the two coordinate points. The resulting distance is */ /* then printed onto the screen with two decimal places. */ printf("\n Please enter any two coordinate pairs. (Ex. x y x y)\n"); scanf("%f%f%f%f", &x1, &y1, &x2, &y2); printf("\n(%.2f ,%.2f) (%.2f ,%.2f)\n", x1, y1, x2, y2); distance = sqrt(((x2-x1)*(x2-x1)) + ((y2-y1)*(y2-y1))); printf("\nDistance = %.2f\n", distance); return 0; } int trig(void) { float angle_deg, angle_rad, angle_sin, angle_cos, angle_tan; /* Defines variables as type float */ printf("\nPlease enter the angle, in degrees.\n"); scanf("%f", &angle_deg); angle_rad = angle_deg * PI / 180.0; angle_sin = sin(angle_rad); angle_cos = cos(angle_rad); angle_tan = tan(angle_rad); printf("sin(%.1f) = %f", angle_deg, angle_sin); printf("cos(%.1f) = %f", angle_deg, angle_cos); printf("tan(%.1f) = %f", angle_deg, angle_tan); return 0; }