10 - a). Design, develop and implement a C/C++/Java program to simulate a numerical calculator.
lab10a.c PROGRAM
#include <stdio.h>
int main()
{
char operator;
float num1, num2, result;
printf("Simulation of a Simple Calculator\n\n");
printf("Enter two numbers \n");
scanf("%f %f", &num1,&num2);
fflush(stdin);
printf("\nEnter the operator [+,-,*,/] \n");
scanf("%s", &operator);
switch(operator)
{
case '+': result = num1 + num2; break;
case '-': result = num1 - num2; break;
case '*': result = num1 * num2; break;
case '/': result = num1 / num2; break;
default : printf("Error in operation"); break;
}
printf("\n%.2f %c %.2f = %.2f\n", num1, operator, num2, result);
}
lab10a.c PROGRAM
#include <stdio.h>
int main()
{
char operator;
float num1, num2, result;
printf("Simulation of a Simple Calculator\n\n");
printf("Enter two numbers \n");
scanf("%f %f", &num1,&num2);
fflush(stdin);
printf("\nEnter the operator [+,-,*,/] \n");
scanf("%s", &operator);
switch(operator)
{
case '+': result = num1 + num2; break;
case '-': result = num1 - num2; break;
case '*': result = num1 * num2; break;
case '/': result = num1 / num2; break;
default : printf("Error in operation"); break;
}
printf("\n%.2f %c %.2f = %.2f\n", num1, operator, num2, result);
}
OUTPUT :( click on image to zoom )
No comments:
Post a Comment