In this tutorial you will learn about the C Program to Find Area of a Right Angled Triangle and its application with practical example.
C Program to Find Area of a Right Angled Triangle
In this tutorial, we will learn to create a C program that will Find the Area of a Right Angled Triangle in C programming.
Prerequisites
Before starting with this tutorial, we assume that you are the best aware of the following C programming topics:
- Operators in C Programming.
- Basic Input and Output function in C Programming.
- Basic C programming.
- While loop in C programming.
- Conditional Statements in C programming.
Algorithm:-
1 2 3 4 5 6 7 8 9 |
1. Declaring the required variables for the program. 2. Taking the input height, width of the <strong> right-angled </strong>triangle. 3. Calculating the area of the <strong> right-angled </strong>triangle using the code. 4. Printing the area of an <strong> right-angled</strong> triangle. 5. End the program. |
Program description:-
In today’s tutorial, we will create a program, that will calculate the area of a right-angled triangle using C programming. First, take the input width, height of the right-angled triangle by the user. Then we will calculate the area of that right-angled triangle using the mathematical expression. At last, we will print the area of a right-angled triangle.
Program Code:-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
/* C Program to find Area of a Right Angled Triangle Example */ //including the required header files. #include<stdio.h> #include<math.h> int main() { //Declaring the required variable for the program. float width, height, c, Area, Perimeter; //width = it will hold the width of the triangle. //height = it will hold the height of triangle //Area = it will hold the value for the Area of the triangle. //Perimeter = it will hold the value for the Perimeter. //taking the input from the user for the program printf("\n Please Enter height and width of the right angled triangle\n"); //scanning the width,height of the triangle. scanf("%f%f",&width, &height); //calculating the area of the right angled triangle. Area = 0.5 * width * height; c = sqrt((width*width) + (height*height)); //calculating the Perimeter of the right angled triangle. Perimeter = width + height + c; //Printing the Area of right angled triangle printf("\n Area of right angled triangle is: %.2f\n",Area); //Printing the Other side of right angled triangle printf("\n Other side of right angled triangle is: %.2f\n",c); //Printing the Perimeter of right angled triangle printf("\n Perimeter of right angled triangle is: %.2f\n", Perimeter); return 0; } |
Output:-
In the above program, we have first initialized the required variable.
- width = it will hold the integer value for the input width of the right-angled triangle.
- height = it will hold the integer value for the input height of the right-angled triangle.
- Area = it will hold the integer value for the area of a right-angled triangle.
- Perimeter = it will hold the integer value for the perimeter of a right-angled triangle.
Input the height, width of the right-angled triangle.
Code to calculate the area of the right-angled triangle.
Printing output the area of the right-angled triangle.