Area of tringle
#include <iostream>
#include <cmath>
using namespace std;
int main() {
int choice;
cout << "Choose method to calculate area of triangle:\n";
cout << "1. Using base and height\n";
cout << "2. Using three sides (Heron's formula)\n";
cout << "Enter choice (1 or 2): ";
cin >> choice;
if (choice == 1) {
double base, height, area;
cout << "Enter base: ";
cin >> base;
cout << "Enter height: ";
cin >> height;
area = 0.5 * base * height;
cout << "Area of triangle = " << area << endl;
else if (choice == 2) {
double a, b, c, s, area;
cout << "Enter three sides of the triangle: ";
cin >> a >> b >> c;
// semi-perimeter
s = (a + b + c) / 2.0;
// Heron's formula
area = sqrt(s * (s - a) * (s - b) * (s - c));
cout << "Area of triangle = " << area << endl;
else {
cout << "Invalid choice!" << endl;
return 0;
Surface area and volume of sphere
#include <iostream>
#include <cmath>
using namespace std;
int main() {
double radius, surfaceArea, volume;
const double PI = 3.141592653589793;
cout << "Enter the radius of the sphere: ";
cin >> radius;
// Surface area of sphere = 4πr²
surfaceArea = 4 * PI * radius * radius;
// Volume of sphere = (4/3)πr³
volume = (4.0 / 3.0) * PI * pow(radius, 3);
cout << "Surface Area of sphere = " << surfaceArea << endl;
cout << "Volume of sphere = " << volume << endl;
return 0;
C++ program to calculate the surface area and volume of a cuboid:
#include <iostream>
using namespace std;
int main() {
double length, width, height;
double surfaceArea, volume;
cout << "Enter length of cuboid: ";
cin >> length;
cout << "Enter width of cuboid: ";
cin >> width;
cout << "Enter height of cuboid: ";
cin >> height;
// Surface Area of cuboid = 2(lb + bh + hl)
surfaceArea = 2 * (length * width + width * height + height * length);
// Volume of cuboid = l × b × h
volume = length * width * height;
cout << "Surface Area of cuboid = " << surfaceArea << endl;
cout << "Volume of cuboid = " << volume << endl;
return 0;
Greatest number of ten numbers
#include <iostream>
using namespace std;
int main() {
int numbers[10];
int greatest;
cout << "Enter 10 different numbers: " << endl;
// Input 10 numbers
for (int i = 0; i < 10; i++) {
cin >> numbers[i];
// Assume the first number is greatest initially
greatest = numbers[0];
// Compare with other numbers
for (int i = 1; i < 10; i++) {
if (numbers[i] > greatest) {
greatest = numbers[i];
cout << "The greatest number is: " << greatest << endl;
return 0;