answersLogoWhite

0

Here's a simple C program to create a basic calculator using pointer variables:

#include <stdio.h>

void calculate(int *a, int *b, char op) {
    switch(op) {
        case '+': printf("Sum: %d\n", *a + *b); break;
        case '-': printf("Difference: %d\n", *a - *b); break;
        case '*': printf("Product: %d\n", *a * *b); break;
        case '/': 
            if (*b != 0)
                printf("Quotient: %d\n", *a / *b);
            else
                printf("Error: Division by zero.\n");
            break;
        default: printf("Invalid operator.\n");
    }
}

int main() {
    int num1, num2;
    char operator;
    printf("Enter two numbers: ");
    scanf("%d %d", &num1, &num2);
    printf("Enter operator (+, -, *, /): ");
    scanf(" %c", &operator);
    calculate(&num1, &num2, operator);
    return 0;
}

This program takes two integers and an operator from the user, then uses pointers to perform the corresponding arithmetic operation.

User Avatar

AnswerBot

4w ago

What else can I help you with?

Related Questions

Write c program of menu driven by calculator?

dcdfsadf


How do you write BASIC program to accept variables?

dim a input a


What is algorithm to write algorithm to the program to access a pointer variable in structure?

Here is the algorithm of the algorithm to write an algorithm to access a pointer in a variable. Algorithmically.name_of_the_structure dot name_of_the _field,eg:mystruct.pointerfield


How do you write a c program to design calculator using loop?

Wr


You want to write a simple without using pointer or array c program which will print greatest number when you give 20 number?

i want to write a simple without using pointer or array c program which will print greatest number when i give 20 number .........How far have you gotten so far?


What are the feutures of a good c program?

c program is fast and efficient.And c programm can be write with vareity of type variables and operations.


How do you write a program in C plus plus plus plus How do you write a program in C to swap two variables without using the third oneo swap two variables without using the third one?

To swap two variables without using a third variable, use exclusive or manipulation... a ^= b; b ^= a; a ^= b;


How do you write a program in Perl to swap two variables without using the third one?

Use list assignment i.e. for two variables $a, $b: ($a,$b) = ($b,$a)


Write C program using functions to simulate a Calculator with the basic functions - square root and reciprocal?

trytytytytytytytytrf 6 bcvvtgujhy6


Why is it important to know the proper data types in declaring variables?

If you do not know then you cannot write a program. The compiler is not clairvoyant so it cannot do it for you.


How do you write a program in C to swap two variables without using the third one using XOR?

a=a^b; b=a^b; a=a^b;


What is the biggest number you can write on a calculator?

This will depend on the type of calculator you have. This will depend on the type of calculator you have.