Submitted by: Submitted by jselga23
Views: 42
Words: 332
Pages: 2
Category: Science and Technology
Date Submitted: 12/07/2014 04:15 PM
Area of a Triangle
Program Description:
This program is designed to find the area of a triangle. The user will input a positive number for the base and the height. The program will then use the area of a triangle formula (area = ½ x b x h). The program will then use the numbers that the user entered and the area will be calculated.
Analysis:
I will define two integers which are base and height. I will then float area which the program will use the area of a triangle formula to calculate. The area of a triangle formula will use the numbers the user entered for the base and the height and multiply them along with (½). The area of a triangle is as follows:
area = 0.5* base * height
For example
Base = 6
Height = 12
area = 0.5 * 6 * 12
area = 0.5 * 6 = 3
area = 3 * 12 = 36
area = 36
Test Plan:
Test Case | Input | Expected Outcome |
1 | Base = 6Height = 12 | Area of the triangle is 36 |
Pseudocode
//This program will calculate the area of a triangle using the area of a triangle formula
//Start main program
Main
//Declare Variables
Base, Height
//Float the area
Area
//String statement for base and height
print “Enter the base of the triangle”
print “Enter the height of the triangle”
//Area of triangle formula
area = 0.5 x base x height
//End main program
End Program
C Code:
//C Code
//This program will calculate the area of a triangle using the area of a triangle formula
//Developer: Justin Selga
//Date: November 30, 2014
#include <stdio.h>
int main(void) {
/*variable definition:*/
int base, height;
float area;
printf("\nEnter the base of Right Angle Triangle : ");
scanf("%d", &base);
printf("\nEnter the height of Right Angle Triangle : ");
scanf("%d", &height);
//Area of Triangle formula
area = 0.5 * base * height;
printf("\nArea of Right Angle Triangle : %f", area);
return 0;
}
The input values for this run was:
6
12...