labs 1-6: init

Signed-off-by: Amneesh Singh <natto@weirdnatto.in>
This commit is contained in:
2022-12-24 14:03:08 +05:30
commit ad185c994e
26 changed files with 2250 additions and 0 deletions

28
lab1/2.cpp Normal file
View File

@@ -0,0 +1,28 @@
#include <cmath>
#include <iostream>
// Triangle
double area(double a, double b, double c) {
double s = (a + b + c) / 2;
return std::sqrt(s * (s - a) * (s - b) * (s - c));
}
// Rectangle
double area(double a, double b) { return a * b; }
// Circle
double area(double a) { return M_PI * a * a; }
int main() {
double a = 3, b = 4, c = 5;
std::cout << "Area of a triangle with sides " << a << ", " << b << " and "
<< c << ": " << area(a, b, c) << std::endl
<< "Area of rectangle with sides " << a << " and " << b << ": "
<< area(a, b) << std::endl
<< "Area of circle with radius " << a << ": " << area(a)
<< std::endl;
return 0;
}