Home / Programs / Program to find angles of a triangle
🚀 Programming Example

Program to find angles of a triangle

👁 6,391 Views
💻 Practical Program
📘 Step Learning
Write a C Program to input two angles from user and find third angle of the triangle. How to find all angles of a triangle if two angles are given by user using C programming. C program to calculate t

💻 Program Code

/**
 * C program to find all angles of a triangle if two angles are given
 */

#include <stdio.h>

int main()
{
    int a, b, c;

    /* Input two angles of the triangle */
    printf("Enter two angles of triangle: ");
    scanf("%d%d", &a, &b);

    /* Compute third angle */
    c = 180 - (a + b);

    /* Print value of the third angle */
    printf("Third angle of the triangle = %d", c);

    return 0;
}
                        

🖥 Program Output

Enter two angles of triangle: 60 30
Third angle of the triangle = 90
                            

📘 Explanation

Required knowledge

Arithmetic operators,  Data types,  Basic input/output

Properties of triangle

Sum of angles of a triangle is 180°.
Sum of angles of triangle

Let us apply basic math to derive formula for third angle. If two angles of a triangle are given, then third angle of triangle is given by -

Logic to find third angle of a triangle

Step by step descriptive logic to find third angle of a triangle -

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

Master Programming Through Practical Examples

Improve your coding logic, problem-solving skills and programming confidence by practicing real-world examples with explanations.

🎯 How to learn from this example

First understand the algorithm carefully. Then study the program line-by-line and compare it with the output. Finally, review the explanation section to strengthen your logic and programming understanding.

🔥 Practice suggestion

Rewrite the program without looking at the code. Modify values, conditions or logic and run it again. This helps improve confidence and strengthens coding skills much faster.