top of page

CALCULATOR

Writer's picture: Code CrazeCode Craze


#include <stdio.h>

int main() {

float num1, num2;

char operator;


printf("Enter two numbers: ");

scanf("%f %f", &num1, &num2);


printf("Enter an operator (+, -, *, /): ");

scanf(" %c", &operator);


switch(operator) {

case '+':

printf("%.1f + %.1f = %.1f", num1, num2, num1 + num2);

break;

case '-':

printf("%.1f - %.1f = %.1f", num1, num2, num1 - num2);

break;

case '*':

printf("%.1f * %.1f = %.1f", num1, num2, num1 * num2);

break;

case '/':

printf("%.1f / %.1f = %.1f", num1, num2, num1 / num2);

break;

default:

printf("Invalid operator");

}

return 0;

}


1 view0 comments

Recent Posts

See All

Stack Using Queue

A stack can be implemented using two queues in C. The basic idea is to use one queue for enqueue operations and another for dequeue...

Queue Using Stack

A queue can be implemented using two stacks in C. The basic idea is to use one stack for enqueue operations and another for dequeue...

Queue Using Array

#include <stdio.h> #include<stdlib.h> #include<math.h> #define size 5 int queue[size]; int front = -1; int rear = -1; void enque(void);...

Comments


bottom of page