A Program To Enter Three Sides Of A Triangle And Evaluate The Area.

#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
  1. The header file, Standard Input Output related to the input and output operations.
  2. header file for console input and output.
  3. header file for basic mathematical operations.
  4. The main method of the program should always return a value if declared as int.
  5. main function braces opened.
  6. variables to store the sides of the triangle.
  7. print function to print the message.
  8. values accepted from the user.
  9. if block to check the possibility of the triangle, where all sides should be equal to 180 degrees
  10. if block braces opened.
  11. print function to print the message.
  12. if block braces closed.
  13. else block executes if the if block condition is not satisfied.
  14. else block braces, opened.
  15. logic to calculate are.
  16. print function to print the message.
  17. else block braces closed.
  18. as the main class is defined as int, therefore a return value.
  19. main func braces closed.
Snapshot Provided By Soham Malakar

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.

Default image
Soham Malakar
Hello my name is Soham Malakar am currently pursuing BCA Coding is one of my favorite hobbies. I love to code and an enthusiast to learn different types of programming languages. I love to get intoxicated in the world of technology and video games. A quick learner possessing better results.
Articles: 15

Newsletter Updates

Enter your email address below to subscribe to our newsletter

Leave a Reply