Lab Report 01
Experiment Name:
Calculating area and perimeter of a rectangle in C.
Objective:
To write a C program that calculates and displays the area and perimeter of a rectangle,
taking the length and width as input from the user.
Software Required
Computer system
C compiler (GCC, Turbo C++)
Text editor (Notepad++, Visual Studio Code, Codeblocks)
Flow Chart
Algorithm:
Step 1: Start.
Step 2: Declare Variables.
Step 3: Read the length and width of the rectangle.
Step 4: Calculate the area of rectangle
area = length*width;
Step 5: Calculate the perimeter of rectangle
perimeter = 2*(length + width);
Step 6: Print the area and perimeter.
Step 7: End.
Source code:
#include <stdio.h>
int main() {
int length, width, area, perimeter;
printf("Enter the length of the rectangle: ");
scanf("%d", &length);
printf("Enter the width of the rectangle: ");
scanf("%d", &width);
area = length * width;
perimeter = 2 * (length + width);
printf("Area of the rectangle: %d square
units\n", area);
printf("Perimeter of the rectangle: %d
units\n", perimeter);
return 0;
}
Output:
Lab Report 02
Experiment Name:
Finding Area and Circumference of a Circle.
Objective:
To write a C program that calculates the area and circumference of a circle using a
symbolic constant for the value of pi.
Software Required:
Computer system
C compiler (GCC, Turbo C++)
Text editor (Notepad++, Visual Studio Code, Codeblocks)
Algorithm:
Step 1: Start.
Step 2: Declare Variables.
Step 3: Read the radius of a circle.
Step 4: Calculate the area of circle
area=PI*radius*radius;
Step 5: Calculate the circumference of circle
circumference = 2*PI*radius
Step 6: Print the area and circumference.
Step 7: End.
Source code:
#include <stdio.h>
#define PI 3.1416
int main() {
float radius, area, circumference;
printf("Enter the radius of the circle: ");
scanf("%f", &radius);
area = PI * radius * radius;
circumference = 2 * PI * radius;
printf("Area of the circle = %.2f sq units\n", area);
printf("Circumference of the circle = %.2f units\n",
circumference);
return 0;
}
Output:
Lab Report 03
Experiment Name:
Finding Area and Circumference of a triangle.
Objective:
To write a C program that calculates the area and circumference of a triangle using the
given three sides of the triangle.
Software Required:
Computer system
C compiler (GCC, Turbo C++)
Text editor (Notepad++, Visual Studio Code, Codeblocks)
Algorithm:
Step 1: Start.
Step 2: Declare Variables.
Step 3: Read the three sides of a triangle.
Step 4: Calculate the semi-perimeter of the triangle
s = (side1 + side2 + side3) / 2;
Step 5: Calculate the area using Heron's formula
area = sqrt(s * (s - side1) * (s - side2) 1 * (s - side3));
Step 6: Calculate the perimeter of triangle
perimeter = side1 + side2 + side3;
Step 7: Print the area and perimeter.
Step 8: End.
Source code:
#include <stdio.h>
#include <math.h>
int main() {
float side1, side2, side3, s, area, perimeter;
printf("Enter the three sides of the triangle: ");
scanf("%f %f %f", &side1, &side2, &side3);
// Calculate the semi-perimeter
s = (side1 + side2 + side3) / 2;
// Calculate the area using Heron's formula
area = sqrt(s * (s - side1) * (s - side2) * (s - side3));
// Calculate the perimeter
perimeter = side1 + side2 + side3;
printf("Area of the triangle = %.2f sq units\n", area);
printf("Perimeter of the triangle = %.2f units\n", perimeter);
return 0;
}
Output:
Lab Report 04
Experiment Name:
Addition of Three Numbers in C.
Objective:
To write, compile, and execute a C program to calculate the sum of three numbers
entered by the user.
Software Required:
Computer system
C compiler (GCC, Turbo C++)
Text editor (Notepad++, Visual Studio Code, Codeblocks)
Algorithm:
Step 1: Start.
Step 2: Declare Variables.
Step 3: Read the three numbers.
Step 4: Calculate the sum of the three numbers
sum = num1 + num2 + num3;
Step 5: Print the sum.
Step 6: End.
Source code:
#include <stdio.h>
int main() {
int num1, num2, num3, sum;
printf("Enter three numbers: ");
scanf("%d %d %d", &num1, &num2, &num3);
sum = num1 + num2 + num3;
printf("Sum of the numbers = %d\n", sum);
return 0;
}
Output:
Lab Report 05
Experiment Name:
Celsius to Fahrenheit Conversion Using C Programming.
Objective:
To write and execute a C program that converts a given temperature in Celsius to its
equivalent value in Fahrenheit.
Software Required:
Computer system
C compiler (GCC, Turbo C++)
Text editor (Notepad++, Visual Studio Code, Codeblocks)
Algorithm:
Step 1: Start.
Step 2: Declare Variables.
Step 3: Read the celsius temperature .
Step 4: Convert the celsius temperature to fahrenheit.
fahrenheit = (celsius * 9 / 5) + 32;
Step 5: Print the fahrenheit temperature.
Step 6: End.
Source code:
#include <stdio.h>
#include <stdio.h>
int main() {
float celsius, fahrenheit;
printf("Enter temperature in Celsius: ");
scanf("%f", &celsius);
fahrenheit = (celsius * 9 / 5) + 32;
printf("%.2f degree Celsius = %.2f degree Fahrenheit \n", celsius, fahrenheit);
return 0;
}
Output:
Lab Report 06
Experiment Name:
Celsius to Fahrenheit Conversion Using C Programming.
Objective:
To write and execute a C program that converts a given temperature in Celsius to its
equivalent value in Fahrenheit.
Software Required:
Computer system
C compiler (GCC, Turbo C++)
Text editor (Notepad++, Visual Studio Code, Codeblocks)
Algorithm:
Step 1: Start.
Step 2: Declare Variables.
Step 3: Read the fahrenheit temperature .
Step 4: Convert the fahrenheit temperature to celsius.
celsius = (fahrenheit - 32) * 5 / 9;
Step 5: Print the celsius temperature .
Step 6: End.
Source code:
#include <stdio.h>
int main() {
float fahrenheit, celsius;
printf("Enter temperature in Fahrenheit: ");
scanf("%f", &fahrenheit);
celsius = (fahrenheit - 32) * 5 / 9;
printf("%.2f degree Fahrenheit = %.2f degree Celsius", fahrenheit, celsius);
return 0;
}
Output: