Showing posts with label calculator. Show all posts
Showing posts with label calculator. Show all posts

Simple Calculator in C++

This program is a simple calculator that performs addition, subtraction, multiplication, and division.

#include <iostream>

int main() {

    char op;

    double num1, num2;

    std::cout << "Enter operator (+, -, *, /): ";

    std::cin >> op;

    std::cout << "Enter two operands: ";

    std::cin >> num1 >> num2;


    switch(op) {

        case '+':

            std::cout << num1 + num2 << std::endl;

            break;

        case '-':

            std::cout << num1 - num2 << std::endl;

            break;

        case '*':

            std::cout << num1 * num2 << std::endl;

            break;

        case '/':

            if (num2 != 0)

                std::cout << num1 / num2 << std::endl;

            else

                std::cout << "Error! Division by zero." << std::endl;

            break;

        default:

            std::cout << "Invalid operator" << std::endl;

    }

    return 0;

}


Simple Calculator in C

This program is a simple calculator that performs addition, subtraction, multiplication, and division.

#include <stdio.h>

int main() {
    char op;ca
    double num1, num2;
    printf("Enter operator (+, -, *, /): ");
    scanf(" %c", &op);
    printf("Enter two operands: ");
    scanf("%lf %lf", &num1, &num2);
 
    switch(op) {
        case '+':
            printf("%.2lf\n", num1 + num2);
            break;
        case '-':
            printf("%.2lf\n", num1 - num2);
            break;
        case '*':
            printf("%.2lf\n", num1 * num2);
            break;
        case '/':
            if (num2 != 0)
                printf("%.2lf\n", num1 / num2);
            else
                printf("Error! Division by zero.\n");
            break;
        default:
            printf("Invalid operator\n");
    }
    return 0;
}



Simple Calculator in Python

  This program is a simple calculator that performs addition, subtraction, multiplication, and division.

 
op = input("Enter operator (+, -, *, /): ")
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
 
if op == '+':
    print(num1 + num2)
elif op == '-':
    print(num1 - num2)
elif op == '*':
    print(num1 * num2)
elif op == '/':
    if num2 != 0:
        print(num1 / num2)
    else:
        print("Error! Division by zero.")
else:
    print("Invalid operator")

MS Excel Logical Functions

Logical functions in Excel are powerful tools that help you make decisions based on conditions. Whether you're comparing values or testi...

Post Count

Loading...