function c+++
function c+++
int main() {
int x = 3;
cout << "Cube of " << x << " is " << cube(x) << endl;
return 0; }
2 #include <iostream>
return 0.5 * w * h;
int main() {
cout << "Area of triangle: " << triangle(height, base) << endl;
return 0;
3 #include <iostream>
return h * w;
int main() {
float height = 4.0, width = 6.0;
cout << "Area of rectangle: " << rectangle(height, width) << endl;
return 0; }
4 #include <iostream>
return m * x + b;}
int main() {
cout << "Y-coordinate: " << Line(slope, intercept, x_value) << endl;
return 0; }
5 #include <iostream>
if (m1 != m2) {
return 1;
} else {
return 0; }
int main() {
} else {
cout << "The lines do not intersect." << endl; }
return 0; }
6 #include <iostream>
int factorial(int n) {
if (n <= 1)
return 1;
else
int main() {
int number;
if (number < 0) {
cout << "Invalid input. Please enter a positive integer." << endl;
} else {
cout << "Factorial of " << number << " is " << factorial(number) << endl;
return 0; }
7 #include <iostream>
int fibonacci(int n) {
if (n == 0)
return 0;
else if (n == 1)
return 1;
else
int main() {
int number;
if (number < 0) {
cout << "Invalid input. Please enter a non-negative integer." << endl;
} else {
cout << "Fibonacci value at position " << number << " is " << fibonacci(number) << endl;
return 0;
8 #include <iostream>
int factorial(int n) {
if (n <= 1)
return 1;
else
e += 1.0 / factorial(i); }
return e;
int main() {
int n;
cin >> n;
if (n < 0) {
} else {
cout << "Approximation of e using " << n << " terms is: " << e_approx << endl;
return 0;
9 #include <iostream>
bool isPrime(int n) {
if (n <= 1)
return false; }
return true;
10 #include<iostreame>
int main() {
int number;
if (isEven(number))
else
return 0;
11 #include <iostream>
return a + b;
return a - b; }
// Function for multiplication
return a * b;
if (b != 0)
return a / b;
else {
return 0;
int main() {
char op;
switch (op) {
case '+':
case '-':
break;
case '*':
break;
case '/':
break;
default:
return 0; }