Question

In: Computer Science

Q6: (Sides of a Right Triangle) Write a function that reads three nonzero integers and determines...

Q6: (Sides of a Right Triangle) Write a function that reads three nonzero integers and determines whether they are the sides of a right-angled triangle. The function should take three integer arguments and return 1 (true) if the arguments comprise a right-angled triangle, and 0 (false) otherwise. Use this function in a program that inputs a series of sets of integers. Hint: a^2+b^2=C^2 Codes in C please.s

Solutions

Expert Solution

#include <stdio.h>

// Write a function that reads three nonzero integers and

// determines whether they are the sides of a right-angled triangle.

int is_right_angled(int a, int b, int c)

{

    // check if sum of squares of any 2 sides equal to square of third side

    if (a * a + b * b == c * c || b * b + c * c == a * a || a * a + c * c == b * b)

        // return true

        return 1;

    // return false

    return 0;

}

int main()

{

    // input 3 integers.

    int a, b, c;

    printf("Enter 3 sides of triangle: ");

    scanf("%d %d %d", &a, &b, &c);

    if (is_right_angled(a, b, c))

        printf("This is a right-angled triangle\n");

    else

        printf("This is not a right-angled triangle\n");

}

.

Output:

.


Related Solutions

Q6: (Sides of a Right Triangle) Write a function that reads three nonzero integers and determines...
Q6: (Sides of a Right Triangle) Write a function that reads three nonzero integers and determines whether they are the sides of a right-angled triangle. The function should take three integer arguments and return 1 (true) if the arguments comprise a right-angled triangle, and 0 (false) otherwise. Use this function in a program that inputs a series of sets of integers. Hint: a^2+b^2=C^2
(JAVA) Write an application that reads three nonzero values entered by the user and determines and...
(JAVA) Write an application that reads three nonzero values entered by the user and determines and prints whether they could represent the sides of a triangle. Enter three sizes, separated by spaces(decimals values are acceptable): 4.5·5.5·3.5 A triangle could measure 4.50, 5.50, by 3.50.
Write a program that accepts the lengths of three sides of a triangle as inputs. The...
Write a program that accepts the lengths of three sides of a triangle as inputs. The program output should indicate whether or not the triangle is a right triangle. Recall from the Pythagorean theorem that in a right triangle, the square of one side equals the sum of the squares of the other two sides. Use The triangle is a right triangle. and The triangle is not a right triangle. as your final outputs. An example of the program input...
(PYTHON) Write aprogram that prompts user to enter three sides of a triangle....
(PYTHON) Write a program that prompts user to enter three sides of a triangle. The program should determine if the three sides can form a triangle. If the three sides can form a triangle, then determine the type of the triangle.There are three types of triangles: Equilateral triangle (all 3 sides are equal) Isosceles triangle (two sides are equal, the third side is of a different length) Scalene triangle (all 3 sides are of different lengths)   The program should...
Write a main function that reads a list of integers from a user, adds to an...
Write a main function that reads a list of integers from a user, adds to an array using dynamic memory allocation, and then displays the array. The program also displays the the largest element in the integer array. Requirement: Using pointer notation. Please do this with C++
Python: Accumulator pattern and conditionals. Write a function play that takes integers rounds and sides and...
Python: Accumulator pattern and conditionals. Write a function play that takes integers rounds and sides and does the following  Plays round number of rounds, rolling two s-sided dice per round (use roll).  Uses the previous functions to calculate the score of each round  Prints out the dice rolls and the score for each round  Accumulates the score over all rounds  Returns the final score over all rounds. *Write a function result that takes an arguments...
Write an application that reads three integers, adds all three together and computes an average of...
Write an application that reads three integers, adds all three together and computes an average of the three entries and computes any remainder of the integer division. A remainder represents the modulus result of dividing an even by an odd number or vice versa. Display the output. Enter an integer score 3 Enter an integer score 6 Enter an integer score 4 The average of 3, 6, 4 is 4 with a remainder of 1 Press any key to continue...
Assignment: Write an interactive C++·program to determine a type of a triangle based on three sides....
Assignment: Write an interactive C++·program to determine a type of a triangle based on three sides. Have a user input the length of three sides of a triangle. Allow the user to enter the sides in any order. Determine if the entered sides form a valid triangle. The triangle may not have negative sides. The sum of any two sides must be greater than the third side to form a triangle. Determine if the entered sides are part of a...
Argument A Since all triangles have three sides, and an isosceles triangle is a triangle, it...
Argument A Since all triangles have three sides, and an isosceles triangle is a triangle, it follows that an isosceles triangle has three sides. Argument a is: inductive/deductive; valid/invalid/strong/weak; sound/unsound/cogent/uncogent? Argument B There is a large crack in Philadelphia's Liberty Bell. From this, we can conclude that there was a defect in the bell's craftsmanship. Argument B is: inductive/deductive; valid/invalid/strong/weak; sound/unsound/cogent/uncogent? Argument C Paleontologists now agree that the Tyrannosaurus Rex was actually a peaceful, plant-eating dinosaur. Therefore, it is probably...
C++ Write a function that determines if there are three of the same value in a...
C++ Write a function that determines if there are three of the same value in a row in an array. The function returns a bool and is passed an array of ints and it's size as an int. Write a function that determines if there are three of the same line in a row in a file. The function returns a bool and is passed a string which contains the filename. Write a function that determines if there are two...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT