#include <stdio.h>
#include <math.h>


int calculate(int x, int y) {
    int input;
    printf("\nEnter the operation to be performed:\n1 for Addition.\n2 for Subtraction.\n3 for Multiplication.\n4 for Division.\n5 for Power.\n");
    scanf("%d", &input);

    if (input == 1) {
        return x + y;
    } else if (input == 2) {
        return x - y;
    } else if (input == 3) {
        return x * y;
    } else if (input == 4) {
        if (y == 0) {
            printf("Error: Division by zero is not allowed.\n");
            return 0;
        }
        return x / y;
    } else if (input == 5) {
        return pow(x, y);
    } else {
        printf("Invalid input. Please choose a valid operation.\n");
        return 0; 
    }
}

int main() {
    float n1, n2;
    float result;
    printf("Enter the numbers to be calculated: ");
    scanf("%f %f", &n1, &n2);
    result = calculate(n1, n2);
    printf("The result is %.2f.\n", result);

    return 0;
}

Embed on website

To embed this program on your website, copy the following code and paste it into your website's HTML: