w3resource

C Exercises: Find the third angle of a triangle if two are given


10. Triangle Third Angle Calculation

Write a C  program to find the third angle of a triangle if two angles are given.

Pictorial Presentation:

C Input Output: Find the third angle of a triangle if two are given

Sample Solution:

C Code:

#include <stdio.h>
int main()  
{  
    int ang1, ang2, ang3; /*are three angles of a triangle  */
  
    /* Read two angles of the triangle from user separated by comma*/  
    printf("Input two angles of triangle separated by comma : ");  
    scanf("%d, %d", &ang1, &ang2);  
  
     ang3 = 180 - (ang1 + ang2);  /* Calculates the third angle  */
  
    printf("Third angle of the triangle :  %d\n", ang3);  
  
    return 0;  
}  
  

Sample Output:

Input two angles of triangle separated by comma : 50,70                                                       
Third angle of the triangle :  60  

Flowchart:

C Programming Input Output Flowchart: Find the third angle of a triangle if two are given.

For more Practice: Solve these Related Problems:

  • Write a C program to calculate the third angle of a triangle and verify that the sum of angles equals 180 degrees.
  • Write a C program to compute the missing angle of a triangle and output an error message if the provided angles are invalid.
  • Write a C program to determine the third angle of a triangle and classify the triangle as acute, right, or obtuse based on its angles.
  • Write a C program to calculate the missing angle of a triangle and then display all three angles in ascending order.

Go to:


PREV : Basic Arithmetic Operations.
NEXT : C Conditional Statement Exercises Home

C Programming Code Editor:



Have another way to solve this solution? Contribute your code (and comments) through Disqus.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Follow us on Facebook and Twitter for latest update.