Untitled

mail@pastecode.io avatar
unknown
plain_text
7 months ago
1.4 kB
2
Indexable
Never
#include <iostream>

// Hàm nạp chồng cho số nguyên
int absolute(int num) {
    if (num < 0) {
        return -num;
    }
    return num;
}

// Hàm nạp chồng cho số thực
double absolute(double num) {
    if (num < 0.0) {
        return -num;
    }
    return num;
}

int findMax(int a, int b, int c) {
    int maxNumber = a;
    if (b > maxNumber) {
        maxNumber = b; 
    }
    if (c > maxNumber) {
        maxNumber = c; 
    }
    return maxNumber;
}
double findMax(double a, double b, double c) {
    double maxNumber = a; 
    if (b > maxNumber) {
        maxNumber = b; 
    }
    if (c > maxNumber) {
        maxNumber = c; 
    }
    return maxNumber;
}

int findMin(int a, int b, int c) {
    int minNumber = a; 
    if (b < minNumber) {
        minNumber = b; 
    }
    if (c < minNumber) {
        minNumber = c;
    }
    return minNumber;
}

double findMin(double a, double b, double c) {
    double minNumber = a; 
    if (b < minNumber) {
        minNumber = b; 
    }
    if (c < minNumber) {
        minNumber = c; 
    }
    return minNumber;
}

double average(int num1, int num2, int num3) {
    return static_cast<double>(num1 + num2 + num3) / 3;
}

double average(double num1, double num2, double num3) {
    return (num1 + num2 + num3) / 3;
}