Sunday, March 2, 2025

Write a C program to create a calculator that performs basic arithmetic operations

 Here is a simple C program to create a calculator that performs basic arithmetic operations:


#include <stdio.h>


void printMenu() {

    printf("Simple Calculator\n");

    printf("1. Addition\n");

    printf("2. Subtraction\n");

    printf("3. Multiplication\n");

    printf("4. Division\n");

    printf("5. Exit\n");

}


int main() {

    int choice;

    float num1, num2, result;


    while (1) {

        printMenu();

        printf("Enter your choice: ");

        scanf("%d", &choice);


        if (choice == 5) {

            printf("Exiting the calculator. Goodbye!\n");

            break;

        }


        printf("Enter the first number: ");

        scanf("%f", &num1);


        printf("Enter the second number: ");

        scanf("%f", &num2);


        switch (choice) {

            case 1:

                result = num1 + num2;

                printf("%.2f + %.2f = %.2f\n", num1, num2, result);

                break;

            case 2:

                result = num1 - num2;

                printf("%.2f - %.2f = %.2f\n", num1, num2, result);

                break;

            case 3:

                result = num1 * num2;

                printf("%.2f * %.2f = %.2f\n", num1, num2, result);

                break;

            case 4:

                if (num2 != 0) {

                    result = num1 / num2;

                    printf("%.2f / %.2f = %.2f\n", num1, num2, result);

                } else {

                    printf("Error! Division by zero is not allowed.\n");

                }

                break;

            default:

                printf("Invalid choice. Please choose a valid option.\n");

        }

    }


    return 0;

}

```


*Example Use Cases:*

1. Run the program and select option 1 (Addition).

2. Enter two numbers, e.g., 10 and 20.

3. The program will display the result: 10.00 + 20.00 = 30.00.

4. Repeat the process for other arithmetic operations.


*How to Compile and Run:*

1. Save the code in a file named `calculator.c`.

2. Open a terminal or command prompt.

3. Navigate to the directory where you saved the file.

4. Compile the program using `gcc calculator.c -o calculator`.

5. Run the program using `./calculator` (on Linux/macOS) or `calculator.exe` (on Windows).

Holi

 Holi


Holi is a significant festival in Hinduism, celebrated with great enthusiasm and joy. Here are some key aspects of Holi:


History and Significance

Holi is an ancient festival, mentioned in the Puranas and other Hindu scriptures. It celebrates the triumph of good over evil, and the arrival of spring.


The Legend of Holika

The festival is associated with the legend of Holika, a demoness who tried to burn her nephew Prahlad, a devotee of Lord Vishnu. However, Prahlad was saved by his devotion, while Holika was burned.


Celebrations

Holi is celebrated over two days:


1. *Holika Dahan*: Bonfires are lit on the eve of Holi to symbolize the burning of Holika.

2. *Rangwali Holi*: On the second day, people gather to play with colored powders (gulal) and waters, symbolizing the colors of spring.


Traditions and Customs

- *Colors*: Holi is known for its vibrant colors, which are believed to bring good luck and prosperity.

- *Music and Dance*: Traditional Holi songs and dances, like the "Holiya" and "Dola Yatra", are performed during the celebrations.

- *Food*: Traditional Holi delicacies, such as gujiyas, thandai, and malpuas, are prepared and shared.


Regional Variations

Holi is celebrated differently across various regions in India:


- *Braj Holi*: In the Braj region, Holi is celebrated with great fervor, and the festivities last for several days.

- *Dola Yatra*: In West Bengal, Holi is celebrated as "Dola Yatra", with processions and traditional songs.


Modern Celebrations

Holi has become a popular festival globally, with many countries hosting Holi events and celebrations.


Safety Precautions

While celebrating Holi, it's essential to take safety precautions:


- *Use natural colors*: Avoid using synthetic colors, which can harm the skin and eyes.

- *Protect skin and eyes*: Wear protective clothing and eyewear to prevent color stains and eye irritation.

- *Stay hydrated*: Drink plenty of water to stay hydrated during the celebrations.


I hope this information helps you understand and appreciate the vibrant festival of Holi!

Featured posts

स्मार्ट इन्वेस्टिंग फॉर बिगिनर्स:

 स्मार्ट इन्वेस्टिंग फॉर बिगिनर्स:  पैसिव इनकम कमाने का आसान रास्ता"।  इसमें मैंने बताया है कि कैसे छोटी रकम से शुरुआत करके, म्यूचुअल फ...

Popular posts