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

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

Example:
Input first angle: 60
Input 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° i.e. a + b + c = 180° (Where a,b,c are angles of triangles).

Program

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

#include <stdio.h>

int main()
{
    int a, b, c; //a, b, c are three angles of a triangle

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

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

    printf("Third angle of the triangle = %d", c);

    return 0;
} 


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

Happy coding ;)


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
< code >< pre > -- Your source code -- < /pre >< /code > (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