/*********************************************************** pythagorean.ch Pythagorean Theorem This program calculates the length of the missing leg of a right triangle ************************************************************ Copyright 2014 SoftIntegration Inc. http://www.softintegration.com Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 ***********************************************************/ //Initialize variables double a,b,c; char check[80]; //Find out what lengths are given printf("are you given the length of the hypotenuse? "); scanf("%s",&check); //calculate and display the length of the missing leg if((strcmp(check, "no") == 0) || (strcmp(check, "n") == 0))//case of hypotenuse not given { printf("enter the length of one of the legs "); scanf("%lf", &a); printf("enter the length of the other leg "); scanf("%lf", &b); c = sqrt(a * a + b * b); printf("hypotenuse: %lf\n", c); } else if((strcmp(check,"yes") == 0) || (strcmp(check,"y") == 0))//case of hypotenuse is given { printf("enter the length of the hypotenuse "); scanf("%lf", &c); printf("enter the length of the known leg "); scanf("%lf", &b); if (b > c) printf("The leg cannot be longer than the hypotenuse, try again.\n"); else { a = sqrt(c * c - b * b); printf("missing leg: %lf\n", a); } } else //case of neither yes or no is entered printf("you must enter 'yes' or 'no'\n");