0% found this document useful (0 votes)
8 views

Lab 2

The document discusses two questions. Question 1 involves designing an algorithm and C program to calculate the area of a triangle given the base and height. Question 2 involves designing an algorithm and program to convert Celsius to Fahrenheit using the given conversion formula.

Uploaded by

s231143229
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Lab 2

The document discusses two questions. Question 1 involves designing an algorithm and C program to calculate the area of a triangle given the base and height. Question 2 involves designing an algorithm and program to convert Celsius to Fahrenheit using the given conversion formula.

Uploaded by

s231143229
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Question 1

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

Input base and height

Calculate area = ½ x base x height

Display area of triangle

End
INPUT OUTPUT
#include <stdio.h>

int main()
{
float base, height, area;

printf("Enter the base of the


triangle(cm): ");
scanf("%f", &base);

printf("Enter the height of


the triangle(cm): ");
scanf("%f", &height);

area = 0.5 * base * height;

printf("The area of the


triangle (cm): %.2f\n", 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

where C is the temperature in Celsius and F the temperature in Fahrenheit.

(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

Calculate F=(9.0/5.0*C) +32 in


Fahrenheit.

Display the temperature in


Fahrenheit

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 }

You might also like