w3resource logo


C Programming Exercises

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

Secondary Nav

C Input Output statement: Exercise-10 with Solution

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

Test data : 50, 70

Expected Output :
Third angle of the triangle : 60

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;  
}    

Solution

#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;  
}

Improve this sample solution and post your code through Disqus.



Join our Question Answer community to learn and share your programming knowledge.

Help the community:

PHP: Loop

JavaScript: Delete duplicates in an array

Oracle: Round the number