#include<stdio.h> //header file, Standard Input Outpur related to the input and output operations #include<conio.h.> //header file for console input and output #include<math.h> //header file for basic mathematical operations int main() //main method of the program which should always return a value if declared as int { //main func braces opened int s1,s2,s3; //variables to store the sides of the triangle printf("Enter the sides of the triangle"); //print func to print the message scanf("%d%d%d",&s1,&s2,&s3); //values accepted from user if((s1+s2+s3)!=180) //if block to check the possibility of triangle, where all sides should be equal to 180 degrees { //if block braces opened printf("\nTriangle not possible"); //print func to print the message } //if block braces closed Else //else block, executes if the if block condition is not satisfied { //else block braces opened int a=(s1+s2+s3)/2; //logic to calculate are int area=sqrt(a*(a-s1)*(a-s2)*(a-s3)); //logic to calculate area printf("\nThe area of the triangle is %d",area); //print func to print the message } //else block braces closed return 0; //as main class is defined as int, therefore an return value } //main func braces closed
- The header file, Standard Input Output related to the input and output operations.
- header file for console input and output.
- header file for basic mathematical operations.
- The main method of the program should always return a value if declared as int.
- main function braces opened.
- variables to store the sides of the triangle.
- print function to print the message.
- values accepted from the user.
- if block to check the possibility of the triangle, where all sides should be equal to 180 degrees
- if block braces opened.
- print function to print the message.
- if block braces closed.
- else block executes if the if block condition is not satisfied.
- else block braces, opened.
- logic to calculate are.
- print function to print the message.
- else block braces closed.
- as the main class is defined as int, therefore a return value.
- main func braces closed.
This was a program to calculate the area of a triangle using sides, hope it worked to clear your to query on the question.
Please write comments or WhatsApp if you find anything incorrect, or you want to share more information about the topic discussed above.