0% found this document useful (0 votes)
83 views

Calculator

This program creates a scientific calculator that can perform 4 basic operations: addition, subtraction, multiplication, division, as well as calculate cosine, sine, tangent and exponents. It uses a switch statement to evaluate the user's choice of operation and prompts them to input values to calculate. The result is then printed for each case. The program uses standard math library functions like pow, cos, sin and tan to evaluate trigonometric and exponent operations.

Uploaded by

akhil221
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
83 views

Calculator

This program creates a scientific calculator that can perform 4 basic operations: addition, subtraction, multiplication, division, as well as calculate cosine, sine, tangent and exponents. It uses a switch statement to evaluate the user's choice of operation and prompts them to input values to calculate. The result is then printed for each case. The program uses standard math library functions like pow, cos, sin and tan to evaluate trigonometric and exponent operations.

Uploaded by

akhil221
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

//program to make a scientific calculator that performs atleast 4 scientific

operations..

#include<stdio.h>
#include<conio.h>
#include<math.h>
#define pi 3.14159
void main()

{
clrscr();
int n;
float a,i,j;
char choice;
printf(“WELCOME TO THE SCIENTIFIC CALULATOR”);
again:
printf(“Enter + for addition”);
printf(“Enter - for subtraction”);
printf(“Enter * for multiplication”);
printf(“Enter / for division”);
printf(“Enter % for remainder”);
printf(“Enter c for finding cos of the number”);
printf(“Enter s for finding sine of the number”);
printf(“Enter t for finding tan of the number”);
printf(“Enter q for raising 2nd number to the power of 1st number”);
printf(“And enter e to exit the calculator”);

switch(choice)

{
case ‘+’:
printf("\nEnter any two numbers to be added ");
scanf("%f%f",&i,&j);
a=i+j;
printf("\nThe result of %.f+%.f=%.f ",i,j,a);
break;
case ‘-’:
printf("\nEnter any two numbers to be subtracted ");
scanf("%f%f",&i,&j);
a=i-j;
printf("The result of %.f-%.f=%.f\n",i,j,a);
break;
case ‘*’:
printf(" \nEnter any two numbers to be multiplied ");
scanf("%f%f",&i,&j);
a=i*j;
printf("\nThe result of %.fx%.f=%.f",i,j,a);
break;
case ‘/’:
abcd:
printf("\nEnter numerator and denominator ");
scanf("%f%f",&i,&j);
if(j==0.0)
{
printf("denominator cant be zero");
goto abcd:
}
else
{
a=i/j;
printf("The result of %.f/%.f=%.f\n",i,j,a);
}
break;
case ‘c’:
printf("\nEnter the value of the angle in degrees");
scanf("%f",&b);
i=b*pi/180;
printf(" The cosine value of the angle is: %f ",cos(i));
break;
case ‘s’:
printf("\nEnter the value of the angle in degrees");
scanf("%f",&b);
i=b*pi/180;
printf(" The sine value of the angle is: %f ",sin(i));
break;
case ‘t’:
printf("\nEnter the value of the angle in degrees");
scanf("%f",&b);
i=b*pi/180;
printf(" The tangent value of the angle is: %f ",tan(i));
break;
case ‘q’:
printf(" Enter the base and index");
scanf("%f%f",&a,&i);
a=pow(i,j);
printf(" The number %f raised to power %f is : %f ",i,j,a);
break;
case ‘e’:
goto end;
break;
default:
printf(" Incorrect input");
goto again;
}
end:
getch();
}

You might also like