Table of Contents
show
Building Scientific Calculator
#include<stdio.h>
#include<conio.h>
#include<math.h>
int main()
{
int choice, i, a, b,e;
double x, y, result,val;
do
{
printf("\nSelect your operation (0 to exit):\n");
printf("1. Addition\n2. Subtraction\n3. Multiplication\n4. Division\n");
printf("5. Arc cosine \n 6. Arc sine \n 7. Arc tan \n 8. Arc tan 2\n 9. cos \n 10. hyperbolic cos \n 11. sin \n 12. hyperbolic sine \n 13. tan \n 14. hyperbolic tangent\n");
printf("15.exp \n 16. frexp \n 17. ldexp \n 18. log \n 19. log10 \n 20. pow \n 21. sqrt\n");
printf("22.ceil \n 23. fabs \n 24. floor \n 25. fmod \n");
printf("Choice: ");
scanf("%d", &choice);
switch(choice)
{
case 1:
printf("Enter X: ");
scanf("%lf", &x);
printf("\nEnter Y: ");
scanf("%lf", &y);
result = x + y;
printf("\nResult: %lf", result);
break;
case 2:
printf("Enter X: ");
scanf("%lf", &x);
printf("\nEnter Y:");
scanf("%lf", &y);
result = x-y;
printf("\nResult: %lf", result);
break;
case 3:
printf("Enter X: ");
scanf("%lf", &x);
printf("\nEnter Y: ");
scanf("%lf", &y);
result = x * y;
printf("\nResult: %lf", result);
break;
case 4:
printf("Enter X: ");
scanf("%lf", &x);
printf("\nEnter Y: ");
scanf("%lf", &y);
result = x / y;
printf("\nResult: %lf", result);
break;
case 5:
printf("Enter X: ");
scanf("%lf", &x);
val = 180.0 / 3.14;
result = acos(x) * val;
printf("The arc cosine of %lf is %lf degrees", x, result);
break;
case 6:
printf("Enter X: ");
scanf("%lf", &x);
val = 180.0 / 3.14;
result = asin(x) * val;
printf("The arc sin of %lf is %lf degrees", x, result);
break;
case 7:
printf("Enter X: ");
scanf("%lf", &x);
val = 180.0 / 3.14;
result = atan(x) * val;
printf("The arc tan of %lf is %lf degrees", x, result);
break;
case 8:
printf("Enter X: ");
scanf("%lf", &x);
printf("\nEnter Y: ");
scanf("%lf", &y);
val = 180.0 / 3.14;
result = atan2(y, x)*val;
printf("The tangent inverse for %lf and %lf is %lf degrees", y,x,result);
break;
case 9:
printf("Enter X: ");
scanf("%lf", &x);
val = 3.14 / 180.0;
result = cos( x*val );
printf("The cosine of %lf is %lf degrees\n", x, result);
break;
case 10:
printf("Enter X: ");
scanf("%lf", &x);
result = cosh( x );
printf("The hyperbolic cosine of %lf is %lf degrees\n", x, result);
break;
case 11:
printf("Enter X: ");
scanf("%lf", &x);
val = 3.14 / 180.0;
result = sin( x*val );
printf("The sine of %lf is %lf degrees\n", x, result);
break;
case 12:
printf("Enter X: ");
scanf("%lf", &x);
result = tanh( x );
printf("The hyperbolic tan of %lf is %lf degrees\n", x, result);
break;
case 13:
printf("Enter X: ");
scanf("%lf", &x);
val = 3.14 / 180.0;
result = tan( x*val );
printf("The tan of %lf is %lf degrees\n", x, result);
break;
case 14:
printf("Enter X: ");
scanf("%lf", &x);
result = tanh( x );
printf("The hyperbolic tan of %lf is %lf degrees\n", x, result);
break;
case 15:
printf("Enter X: ");
scanf("%lf", &x);
result = exp( x );
printf("The exponential of %lf is %lf \n", x, result);
break;
case 16:
printf("Enter X: ");
scanf("%lf", &x);
result = frexp( x, &e );
printf("x = %.2lf = %.2lf * 2^%d\n", x, result, e);
break;
case 17:
printf("Enter X: ");
scanf("%lf", &x);
printf("\nEnter e: ");
scanf("%d", &e);
result = ldexp(x,e);
printf("%lf * 2^%d = %lf\n", x, e, result);
break;
case 18:
printf("Enter X: ");
scanf("%lf", &x);
result = log( x );
printf("The log of %lf is %lf \n", x, result);
break;
case 19:
printf("Enter X: ");
scanf("%lf", &x);
result = log10( x );
printf("The log10 of %lf is %lf \n", x, result);
break;
case 20:
printf("Enter X: ");
scanf("%lf", &x);
printf("\nEnter y: ");
scanf("%lf", &y);
result = pow(x,y);
printf("The power of %lf ^ %lf is %lf \n", x,y, result);
break;
case 21:
printf("Enter X: ");
scanf("%lf", &x);
result = sqrt( x );
printf("The square root of %lf is %lf \n", x, result);
break;
case 22:
printf("Enter X: ");
scanf("%lf", &x);
result = ceil( x );
printf("The ceil of %lf is %lf \n", x, result);
break;
case 23:
printf("Enter X: ");
scanf("%lf", &x);
result = fabs( x );
printf("The absolute value of %lf is %lf \n", x, result);
break;
case 24:
printf("Enter X: ");
scanf("%lf", &x);
result = floor( x );
printf("The floor of %lf is %lf \n", x, result);
break;
case 25:
printf("Enter X: ");
scanf("%lf", &x);
printf("Enter Y: ");
scanf("%lf", &y);
result = fmod( x,y );
printf("The modulo of %lf is %lf \n", x, result);
break;
default:
printf("\nInvalid Choice!");
}
} while(choice);
return 0;
}
Output
Select your operation (0 to exit):
1. Addition
2. Subtraction
3. Multiplication
4. Division
5. Arc cosine
6. Arc sine
7. Arc tan
8. Arc tan 2
9. cos
10. hyperbolic cos
11. sin
12. hyperbolic sine
13. tan
14. hyperbolic tangent
15.exp
16. frexp
17. ldexp
18. log
19. log10
20. pow
21. sqrt
22.ceil
23. fabs
24. floor
25. fmod
Choice: 22
Enter X: 2.3
The ceil of 2.300000 is 3.000000
Select your operation (0 to exit):
1. Addition
2. Subtraction
3. Multiplication
4. Division
5. Arc cosine
6. Arc sine
7. Arc tan
8. Arc tan 2
9. cos
10. hyperbolic cos
11. sin
12. hyperbolic sine
13. tan
14. hyperbolic tangent
15.exp
16. frexp
17. ldexp
18. log
19. log10
20. pow
21. sqrt
22.ceil
23. fabs
24. floor
25. fmod
Choice: 0
Invalid Choice!
Views: 0