কম্পিউটার টিউটোরিয়াল

C/C++-এ সিম্পল ক্যালকুলেটর প্রোগ্রাম


একটি সিম্পল ক্যালকুলেটর মৌলিক অপারেশনগুলো করে: '+' (যোগ), '-' (বিয়োগ), '*' (গুণ), '/' (ভাগ)। ক্যালকুলেটর এই অপারেশনগুলো দ্রুত করে। এখানে সুইচ স্টেটমেন্ট ব্যবহার করে ক্যালকুলেটর বানানো হয়েছে।

নমুনা

Operator - '+' => 34 + 324 = 358
Operator - '-' => 3874 - 324 = 3550
Operator - '*' => 76 * 24 = 1824
Operator - '/' => 645 / 5 = 129

উদাহরণ কোড

#include <iostream>
using namespace std;

int main() {
    char op = '+';
    float a = 63, b = 7;
    // cout << "Enter operator either + or - or * or /: ";
    // cin >> op;
    cout << "The operator is " << op << endl;
    // cout << "Enter two operands: ";
    // cin >> a >> b;
    cout << "a = " << a << " b = " << b << endl;
    switch(op) {
        case '+':
            cout << "Sum of " << a << " and " << b << " is " << a+b;
            break;
        case '-':
            cout << "Difference of " << a << " and " << b << " is " << a-b;
            break;
        case '*':
            cout << "Product of " << a << " and " << b << " is " << a*b;
            break;
        case '/':
            cout << "Division of " << a << " and " << b << " is " << a/b;
            break;
        default:
            cout << "Error! operator is not correct";
            break;
    }
    return 0;
}

আউটপুট

The operator is +
a = 63 b = 7
Sum of 63 and 7 is 70

  1. C/C++ প্রোগ্রামে অ্যারে (Arrays)

  2. C/C++ টার্নারি অপারেটর (?:) — সংক্ষিপ্ত শর্তাধীন এক্সপ্রেশন

  3. C/C++ প্রোগ্রামে লিনিয়ার সার্চ অ্যালগরিদম

  4. সি/সি++ প্রোগ্রাম: nth ক্যাটালান সংখ্যা (Catalan Number)