Calculator

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 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