- //Purpose: This program takes three positive intergers and outputs the type of triangle
- //it is as well as the area of the triangle.
- //Name: Daniel Smith
- //Section - 20737,20738
- //Lab 1B
- #include <stdio.h>
- #include <math.h>
- #include <iostream>
- using std::cout;
- using std::endl;
- using std::cin;
- int is_triangle(int a, int b, int c) // function to check if it is a valid triangle
- {
- // Property used : Sum of two sides is always greater than the third side
- if ((a + b) <= c)
- {
- return 0;
- }
- if ((b + c) <= a)
- {
- return 0;
- }
- if ((c + a) <= b)
- {
- return 0;
- }
- return 1;
- }
- float area_triangle(int a, int b, int c) // function to calculate area
- {
- float s = (a + b + c) / 2;
- float area = sqrt((s) * (s - a) * (s - b) * (s - c));
- return area;
- }
- int main()
- {
- int a, b, c;
- printf("Enter three positive integers : ");
- scanf_s("%d %d %d", &a, &b, &c);
- int ans = is_triangle(a, b, c);
- if (!ans)
- {
- printf("The integers %d, %d and %d are not valid sides of triangle", a, b, c);
- }
- if (ans)
- {
- if ((a == b) && (a == c))
- {
- printf("It is an equilateral triangle\n");
- }
- else if (a != b && b != c && c != a)
- {
- printf("It is a scalene triangle\n");
- }
- else
- {
- printf("It is an isosceles triangle\n");
- }
- float area = area_triangle(a, b, c);
- printf("Area of the triangle is %f", area);
- }
- {
- char choice;
- while (true)
- {
- cout << "\nWould you like to perform other calculation?(Y/N)" << endl;
- cin >> choice;
- if (choice == 'Y' || choice == 'y') {
- return main();
- }
- else if (choice == 'N' || choice == 'n') {
- return false;
- }
- }
- }
- return 0;
- }
[text] lol
Viewer
*** This page was generated with the meta tag "noindex, nofollow". This happened because you selected this option before saving or the system detected it as spam. This means that this page will never get into the search engines and the search bot will not crawl it. There is nothing to worry about, you can still share it with anyone.
Editor
You can edit this paste and save as new: