C Program to Find Third Angle of a Triangle

In this tutorial, i am going to show you how to find the third angle of a triangle if two angles are given in c programs.

All C Programs and Algorithm to Find Third Angle of a Triangle

  • Algorithm to find third angle of a triangle
  • C Program to Find Third Angle of a Triangle

Algorithm to find third angle of a triangle

Follow the below given algorithm to write a program to find the third angle of a triangle if two angles are given; as follows:

  1. Input two angles of triangle from user and store it in some variables.
  2. Compute third angle of triangle using formula c = 180 - (a + b).
  3. Print value of third angle i.e. print c.

C Program to Find Third Angle of a Triangle

/* 
 * Given two angles of a triangle, Here is the 
 * C program to find third angle
 */ 
   
#include <stdio.h>  
#define ANGLE_SUM 180
 
int main() {
 /* Three angles of a triangle */
    float a1, a2, a3;  
   
    /* 
     * Take two angles as input from user 
     */ 
    printf("Enter Two Angles of a Triangle :- ");  
    scanf("%f %f", &a1, &a2);  
   
    /* Sum of all three angles of a triangle is 180 degrees */ 
    a3 = ANGLE_SUM - (a1 + a2);  
   
    printf("Third Angle = %0.4f", a3);  
   
    return 0;  
}

The output of the above c program; as follows:

Enter Two Angles of a Triangle :- 60 30
Third Angle = 90.0000

Be First to Comment

Leave a Reply

Your email address will not be published.