C program to find angles of triangle if two angles are given

Previous Program Next Program

Write a C Program to input two angles of a triangle 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 the third angle of a triangle if two angles are given.

Example

Input

Enter first angle: 60
Enter second angle: 80

Output

Third angle = 40

Required knowledge

Fundamentals of C, Data types, Talking user input in C

Properties of triangle

We know that sum of all angles of a triangle is 180° .

Sum of angles of a triangle

Hence, by applying basic mathematics we can easily deduct a formula for finding the third angle. The formula for third angle is given by -

Third angle of a triangle

Logic to find third angle of a triangle

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

  1. Read two angles of the triangle from user and store it in some variable say a and b.
  2. Now, apply the formula for finding third angle. Which is c = 180 - (a + b).
  3. Print the value of c. Which is the required third angle of the triangle.

Program to find angles of a triangle

/**
 * 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);

    // Calculate the third angle
    c = 180 - (a + b);

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

    return 0;
} 
Output
Enter two angles of triangle: 60 30
Third angle of the triangle = 90

Happy coding ;)

Recommended posts

Previous Program Next Program
Any doubt or suggestion write here. I will try my best to help. Before posting your code you must escape it to view. To format your source code and use format highlighting, post your source code inside
< pre>< code >----Your Source Code---- < / code > < / pre > (Remove spaces from pre and code tags)

1 comment:

  1. Basic C Program for Computer Programmer who want to learn. If you have simple wish you may visit. To get all update stay with us.
    Outline:
    • Language: C and Simscript.
    • if (Condition) statement and Nested if statement is used to determine the given number is positive, negative, even or odd. Another way we solve this program using if-else-if ladder.
    • When the given condition or expression is true the statement associated with it executed.
    To know details:
    http://www.secufoon.com/write-a-c-program-for-determining-a-number-is-positive-negative-even-or-odd/

    ReplyDelete