-
Notifications
You must be signed in to change notification settings - Fork 1
/
PROG18.C
53 lines (53 loc) · 1.54 KB
/
PROG18.C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
//18. Write a menu-driven program for scientific calculator using switch-case statement. (add, sub, mul, div, module, square, square root, power, log)
#include<stdio.h>
#include<conio.h>
#include<math.h>
int main()
{
float a,b; char c; float p; int result;
printf("This program will calculate addition, substraction, multiplication, division, mod,square, square root, power, log of two integers.\n");
printf("Enter the two number a and b : ");
scanf("%f %f",&a,&b);
printf("Enter the arithmatic sign from following sign (+,-,*,/,%,square=x,square root=y,power=z,log=w) \n Enter sign:");
scanf("%c",&c);
c=getche();
switch(c)
{
case '+':
printf("The answer is : %f",a+b);
break;
case '-':
printf("The answer is : %f",a-b);
break;
case '*':
printf("The answer is : %f",a*b);
break;
case '/':
printf("The answer is : %f",a/b);
break;
case '%':
result=a/b;
if(a<b)
printf("The answer is : 0");
else
printf("The answer is : %f",a-result*b);
break;
case 'x':
printf("The answer for a is: %f and answer for b is : %f",a*a,b*b);
break;
case 'y':
printf("The answer for a is: %f and answer for b is: %f",sqrt(a),sqrt(b));
break;
case 'z':
printf("\nEnter the power : ");
scanf("%f",&p);
printf("The answer for %.3f^%.3f is : %.3f and answer for %.3f^%.3f is : %.3f",a,p,pow(a,p),b,p,pow(b,p));
break;
case 'w':
printf("log(a) is : %f and log(b) is : %f",log(a),log(b));
break;
default:
printf("Invalid Input");
}
return 0;
}