diff --git a/RightTriangleChecker.cpp b/RightTriangleChecker.cpp new file mode 100644 index 0000000..4c07147 --- /dev/null +++ b/RightTriangleChecker.cpp @@ -0,0 +1,56 @@ +// C++ program to check validity of triplets +#include +using namespace std; + +// Function to check pythagorean triplets +bool Triplets(long long a, long long b, long long c) +{ + if (a <= 0 || b <= 0 || c <= 0) + return false; + + vector vec{ a, b, c }; + sort(vec.begin(), vec.end()); + + // Re-initialize a, b, c in ascending order + a = vec[0], b = vec[1], c = vec[2]; + + // Check validation of sides of triangle + if (a + b <= c) + return false; + + long long p1 = a, p2 = c - b; + + // Reduce fraction to simplified form + long long div = __gcd(p1, p2); + p1 /= div, p2 /= div; + + long long q1 = c + b, q2 = a; + + // Reduce fraction to simplified form + div = __gcd(q1, q2); + q1 /= div, q2 /= div; + + // If fraction are equal return + // 'true' else 'false' + return (p1 == q1 && p2 == q2); +} + +// Function that will return 'Yes' or 'No' +// according to the correction of triplets +string checkTriplet(long long a, long long b, long long c) +{ + if (Triplets(a, b, c)) + return "Yes,its a right angled triangle"; + else + return "No,its not a right triangle"; +} + +// Driver code +int main() +{ + long long a,b,c; + cout<<"Enter three sides:"; + cin>>a>>b>>c; + cout << checkTriplet(a, b, c) << endl; + return 0; +} diff --git a/cellphonecompany.cpp b/cellphonecompany.cpp new file mode 100644 index 0000000..061f10b --- /dev/null +++ b/cellphonecompany.cpp @@ -0,0 +1,70 @@ +#include +#include + +using namespace std; +double cost; + +double regularBill() +{ + int minutes; + + cout << "Enter the number of minutes used: "; + cin >> minutes; + + if (minutes <= 50) + minutes = 0; + else + minutes -= 50; + + cost = 10 + minutes * 0.20; + return cost; +} + +double premiumBill() +{ + int minDay, minNight; + double costDay, costNight; + + cout << "Enter the number of minutes used at day and at night (separated by spaces): "; + cin >> minDay >> minNight; + + if (minDay <= 75) + minDay = 0; + else + minDay -= 75; + costDay = 0.10 * minDay; + + if (minNight <= 100) + minNight = 0; + else + minNight -= 100; + costNight = 0.05 * minNight ; + + cost = 10 + costDay + costNight; + + return cost; +} +int main() +{ + char service; + int accnum; + cout << "Enter account number: "; + cin >> accnum; + cout << "Enter 'r' for regular service or 'p' for premium service: "; + cin >> service; + cout << fixed << showpoint << setprecision(2); + + if (service == 'r' || service == 'R') + { + cout << "Cost: $" << regularBill(); + } + else if (service == 'p' || service == 'P') + { + cout << "Cost: $" << premiumBill(); + } + else + cout << "Incorrect input. Try again later."; + + + return 0; +} \ No newline at end of file