20 questions and answers written how kids can improve all their skills

Calculator in C Programming language : This page provides the information about the given title, you can see code about it as well as video lecture about it, that how this work:
This is the video of this lecture , you can search and know about it:
Video
Coding (Free to copy paste)
#include <stdio.h>
int main() {
char operator;
double num1, num2, result;
printf("Enter an operator (+, -, *, /): ");
scanf("%c", &operator);
printf("Enter two operands: ");
scanf("%lf %lf", &num1, &num2);
switch(operator) {
case '+':
result = num1 + num2;
break;
case '-':
result = num1 - num2;
break;
case '*':
result = num1 * num2;
break;
case '/':
if(num2 == 0) {
printf("Error: division by zero");
return 0;
} else {
result = num1 / num2;
break;
}
default:
printf("Invalid operator");
return 0;
}
printf("%.2lf %c %.2lf = %.2lf", num1, operator, num2, result);
return 0;
}
Comments
Post a Comment