Simple Calculator In C Language

Dear Sciaku Learner you are not logged in or not enrolled in this course.

Please Click on login or enroll now button.

If you have any query feel free to chat us!

Happy Coding! Happy Learning!

Here is an example of a simple calculator program written in C language:

Copy code

#include <stdio.h> int main() {    double num1, num2;    char operator;    printf("Enter an operator (+, -, *, /): ");    scanf("%c", &operator);    printf("Enter two operands: ");    scanf("%lf %lf", &num1, &num2);    switch(operator) {        case '+':            printf("%.1lf + %.1lf = %.1lf", num1, num2, num1 + num2);            break;        case '-':            printf("%.1lf - %.1lf = %.1lf", num1, num2, num1 - num2);            break;        case '*':            printf("%.1lf * %.1lf = %.1lf", num1, num2, num1 * num2);            break;        case '/':            printf("%.1lf / %.1lf = %.1lf", num1, num2, num1 / num2);            break;        // operator doesn't match any case constant        default:            printf("Error! operator is not correct");    }        return 0; }

This program prompts the user to enter an operator (one of +, -, *, or /) and two operands. It then performs the specified operation and prints the result to the screen. The program uses a switch statement to determine which operation to perform based on the operator entered by the user.

5. Flow Control

Comments: 0

Frequently Asked Questions (FAQs)

How do I register on Sciaku.com?
How can I enroll in a course on Sciaku.com?
Are there free courses available on Sciaku.com?
How do I purchase a paid course on Sciaku.com?
What payment methods are accepted on Sciaku.com?
How will I access the course content after purchasing a course?
How long do I have access to a purchased course on Sciaku.com?
How do I contact the admin for assistance or support?
Can I get a refund for a course I've purchased?
How does the admin grant access to a course after payment?