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

final lab 2025 mid sem spl

The document outlines six experiments involving basic geometric calculations and number properties using C programming. Each experiment includes software requirements, an algorithm, source code, and expected output. The experiments cover calculating areas and perimeters of shapes, determining odd/even numbers, checking leap years, and finding roots of quadratic equations.

Uploaded by

chandankhulna84
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

final lab 2025 mid sem spl

The document outlines six experiments involving basic geometric calculations and number properties using C programming. Each experiment includes software requirements, an algorithm, source code, and expected output. The experiments cover calculating areas and perimeters of shapes, determining odd/even numbers, checking leap years, and finding roots of quadratic equations.

Uploaded by

chandankhulna84
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 12

Experiment no: 1

Experiment Name: Find the area and perimeter of a rectangle

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;

printf("Enter the length of the rectangle: ");


scanf("%f", &length);
printf("Enter the width of the rectangle: ");
scanf("%f", &width);

area = length * width;


perimeter = 2 * (length + width);

printf("Area of the rectangle: %.2f\n", area);


printf("Perimeter of the rectangle: %.2f\n", perimeter);

return 0;
}

Output:
Experiment no: 2

Experiment Name: Find area and circumference of a circle (Using π as a


symbolic constant)

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: radius, area, circumference.

Step 3: Define the constant π as 3.14159.


Step 4: Read the radius of the circle.
Step 5: Calculate the area of the circle:
area = π * radius * radius;
Step 6: Calculate the circumference of the circle:
circumference = 2 * π * radius;
Step 7: Print the area and circumference.
Step 8: End.
Source Code:

#include <stdio.h>

#define PI 3.14159

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\n", area);


printf("Circumference of the circle: %.2f\n", circumference);

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.

Step 2: Declare variables: a, b, c, s, area, perimeter.

Step 3: Read the three sides of the triangle: a, b, and c.


Step 4: Calculate the semi-perimeter of the triangle:
s = (a + b + c) / 2;
Step 5: Calculate the area using Heron's formula:
area = √(s * (s - a) * (s - b) * (s - c));
Step 6: Calculate the perimeter:
perimeter = a + b + c;
Step 7: Print the area and perimeter.
Step 8: End.
Source Code:

#include <stdio.h>

#include <math.h>

int main()
{
float a, b, c, s, area, perimeter;

printf("Enter the three sides of the triangle: ");


scanf("%f %f %f", &a, &b, &c);

s = (a + b + c) / 2;
area = sqrt(s * (s - a) * (s - b) * (s - c));
perimeter = a + b + c;

printf("Area of the triangle: %.2f\n", area);


printf("Perimeter of the triangle: %.2f\n", perimeter);

return 0;
}

Output:
Experiment no: 4

Experiment Name: Determine whether a number is odd or even

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 variable: number.


Step 3: Read the number.
Step 4: If number % 2 == 0, then
Print "The number is even."
Else,
Print "The number is odd."
Step 5: End.
Source Code:

#include <stdio.h>

int main()
{
int number;

printf("Enter a number: ");


scanf("%d", &number);

if (number % 2 == 0) {
printf("%d is even.\n", number);
} else {
printf("%d is odd.\n", number);
}

return 0;
}

Output:
Experiment no: 5

Experiment Name: Verify whether a given year is a leap year or not

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 variable: year.


Step 3: Read the year.
Step 4: If (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0),
Print "The year is a leap year."
Else,
Print "The year is not a leap year."
Step 5: End.
Source Code:

#include <stdio.h>

int main()
{
int year;

printf("Enter a year: ");


scanf("%d", &year);

if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) {


printf("%d is a leap year.\n", year);
} else {
printf("%d is not a leap year.\n", year);
}

return 0;
}

Output:
Experiment no: 6

Experiment Name: Find all possible roots of a quadratic equation

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: a, b, c, D, root1, root2.


Step 3: Read the coefficients a, b, and c.
Step 4: Calculate the discriminant:
D = b * b - 4 * a * c;
Step 5: If D > 0, then
Calculate and print two real roots:
root1 = (-b + √D) / (2 * a);
root2 = (-b - √D) / (2 * a);
Else if D == 0, then
Calculate and print one real root:
root1 = -b / (2 * a);
Else,
Print "No real roots."
Step 6: End.

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:

You might also like