Calculator
Calculator by Mohit Purohit
C
O
D
E
/*
Creator - Mohit Purohit
Date - 21 Jan. 2022
Time - 8:52 P.M.
*/
#include<stdio.h>
#include<conio.h>
//#include<string.h>
int main()
{
clrscr();
/*
'num1' and 'num2' are 'float' means decimal value.
'op' means operator and 'op' is a 'char' means character.
Then result is also a 'float' value.
*/
float num1;
float num2;
char op;
float result;
const float p=3.14159265;
// User enter the first number means 'num1'.
printf("Enter the first number : ");
scanf("%f",&num1);
// User enter the operator means 'op'.
printf("\nEnter the operator : ");
scanf(" %c",&op);
// User enter the second number means 'num2'.
printf("\nEnter the second number : ");
scanf("%f",&num2);
switch (op)
{
case '-' :
result = num1-num2;
printf("\n%g - %g = %g \n\n\n👦👦I hope this is helpful for you👦👦\n\t - Mohit Purohit \n\n\n\n", num1, num2, result);
break;
case '+' :
result = num1+num2;
printf("\n%g + %g = %g \n\n\n👦👦I hope this is helpful for you👦👦\n\t - Mohit Purohit \n\n\n\n", num1, num2,result);
break;
case 'x' :
result = num1*num2;
printf("\n%g × %g = %g \n\n\n👦👦I hope this is helpful for you👦👦\n\t - Mohit Purohit \n\n\n\n", num1, num2, result);
break;
case '/' :
result = num1/num2;
printf("\n%g ÷ %g = %g \n\n\n👦👦I hope this is helpful for you👦👦\n\t - Mohit Purohit \n\n\n\n", num1, num2, result);
break;
case '%' :
result = num1*num2/100;
printf("\n %g %% %g = %g \n\n\n👦👦I hope this is helpful for you👦👦\n\t - Mohit Purohit \n\n\n\n",num1, num2, result);
break;
case 'p' :
result = num1*p*num2;
printf ("\n%g × Ï€ × %g = %g \n\n\n👦👦I hope this is helpful for you👦👦\n\t - Mohit Purohit \n\n\n\n",num1, num2, result);
break;
default :
printf("\n\n\n\n\n\t SORRY !\nI think you have mistaken. \n\n\n");
}
getchar();
return 0;
}
Comments
Post a Comment