Lab 2
Lab 2
Design an algorithm using flowchart for a program that measure area of triangle. Then,
write a complete C program to implement the algorithm. The program must read the value
of base and height of the triangle entered by users, measure the area of the triangle and
display the result at the end. The formula for triangle area given as follows:
1
area base height
2
Begin
End
INPUT OUTPUT
#include <stdio.h>
int main()
{
float base, height, area;
return 0;
}
Question 2
Write a program to convert the temperature from degrees in Celsius to degrees in
Fahrenheit. The conversion formula given as follows:
F = (9.0/5.0 x C) + 32
(i) Design the algorithm, i.e write the pseudo code and draw the flowchart of
the solution.
(ii) Implement the algorithm designed in (i) in your program. Test and verify
the completed program and write down your completed program.
Begin
Input temperature
Read temperature in
Celcius and store it
in variable C
End
Pseudo Code Input
1. Start
#include<stdio.h>
2. Input temperature in
Celsius
int main()
3. Read the temperature in {
Celsius and store it in float C, F;
the variable C
printf("Enter temperature in
4. Calculate the Celcius\n");
temperature in
scanf("%f", &C);
Fahrenheit using the
F = (9.0/5.0*C) + 32;
formula: F = (9.0/5.0 *
C) + 32
printf("Temperature in
5. Display the temperature Fahrenheit is %f\n", F);
in Fahrenheit
return 0;
6. End }