Tech Unleashed

Wohoo!! We're on YouTube

Monday, 14 February 2022

C program for "Write a program to check whether a triangle is valid or not, when the three angles of the triangle are entered through the keyboard."

Problem: C program for "Write a program to check whether a triangle is valid or not, when the three angles of the triangle are entered through the keyboard."

Logic used :
  • Takes all angles as input
  • Calculate the sum of all three
  • if the sum is equal to 180 then the triangle is valid
  • else the triangle is not valid
Demo:
if((a+b+c)==180){
        printf("The traingle is valid.");
    }else{
        printf("The traingle is not valid.");
    }

C program :

// Program by shyam sunder kanth

#include<stdio.h>

int main(){
    int a,b,c;
    printf("Enter angle A :");
    scanf("%d",&a);
    printf("Enter angle B :");
    scanf("%d",&b);
    printf("Enter angle C :");
    scanf("%d",&c);
    if((a+b+c)==180){
        printf("The traingle is valid.");
    }else{
        printf("The traingle is not valid.");
    }
    return 0;
}

Codes used :
  • #include<stdio.h> : Header file for input output
  • int : Integer data type
  • a,b,c : Variable used
  • printf : Function for displaying message
  • scanf : Function for taking input
  • if-else : Conditional statement
Do comments, If any doubt
Know about me : Shyam Kanth

No comments:

Post a Comment