final lab 2025 mid sem spl
final lab 2025 mid sem spl
Software Requirements:
A computer system
A C compiler (e.g., GCC, Turbo C++)
A text editor or IDE (e.g., Visual Studio Code, Notepad++, Code::Blocks)
Algorithm:
Step 1: Start.
Step 2: Declare variables: length, width, area, perimeter.
Step 3: Read the length and width of the rectangle.
Step 4: Calculate the area of the rectangle:
area = length * width;
Step 5: Calculate the perimeter of the rectangle:
perimeter = 2 * (length + width);
Step 6: Print the area and perimeter.
Step 7: End.
Source Code:
#include <stdio.h>
int main()
{
float length, width, area, perimeter;
return 0;
}
Output:
Experiment no: 2
Software Requirements:
A computer system
A C compiler (e.g., GCC, Turbo C++)
A text editor or IDE (e.g., Visual Studio Code, Notepad++, Code::Blocks)
Algorithm:
Step 1: Start.
#include <stdio.h>
#define PI 3.14159
int main()
return 0;
}
Output:
Experiment no: 3
Experiment Name: Find area and perimeter of a triangle (three sides of the
triangle are given)
Software Requirements:
A computer system
A C compiler (e.g., GCC, Turbo C++)
A text editor or IDE (e.g., Visual Studio Code, Notepad++, Code::Blocks)
Algorithm:
Step 1: Start.
#include <stdio.h>
#include <math.h>
int main()
{
float a, b, c, s, area, perimeter;
s = (a + b + c) / 2;
area = sqrt(s * (s - a) * (s - b) * (s - c));
perimeter = a + b + c;
return 0;
}
Output:
Experiment no: 4
Software Requirements:
A computer system
A C compiler (e.g., GCC, Turbo C++)
A text editor or IDE (e.g., Visual Studio Code, Notepad++, Code::Blocks)
Algorithm:
Step 1: Start.
#include <stdio.h>
int main()
{
int number;
if (number % 2 == 0) {
printf("%d is even.\n", number);
} else {
printf("%d is odd.\n", number);
}
return 0;
}
Output:
Experiment no: 5
Software Requirements:
A computer system
A C compiler (e.g., GCC, Turbo C++)
A text editor or IDE (e.g., Visual Studio Code, Notepad++, Code::Blocks)
Algorithm:
Step 1: Start.
#include <stdio.h>
int main()
{
int year;
return 0;
}
Output:
Experiment no: 6
Software Requirements:
A computer system
A C compiler (e.g., GCC, Turbo C++)
A text editor or IDE (e.g., Visual Studio Code, Notepad++, Code::Blocks)
Algorithm:
Step 1: Start.
Source Code:
#include <stdio.h>
#include <math.h>
int main()
{
float a, b, c, D, root1, root2;
printf("Enter coefficients a, b, c: ");
scanf("%f %f %f", &a, &b, &c);
D = b * b - 4 * a * c;
if (D > 0) {
root1 = (-b + sqrt(D)) / (2 * a);
root2 = (-b - sqrt(D)) / (2 * a);
printf("The roots are real and different.\n");
printf("Root 1 = %.2f\n", root1);
printf("Root 2 = %.2f\n", root2);
} else if (D == 0) {
root1 = -b / (2 * a);
printf("The root is real and the same.\n");
printf("Root = %.2f\n", root1);
} else {
printf("The equation has no real roots.\n");
}
return 0;
}
Output: