Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<conio.h>
- #include<math.h>
- #include<stdlib.h>
- #define PI 3.14159265
- #define KEY "Enter the calculator Operation you want to do:"
- void addition();
- void subtraction();
- void multiplication();
- void division();
- void modulus();
- void power();
- int factorial();
- void calculator_operations();
- void root();
- void exponent();
- void logten();
- void sine();
- void cosine();
- void tangent();
- void secant();
- void cosec();
- int main()
- {
- system("color 4E");
- printf("\t\t\t\t===========================================================\n");
- printf("\t\t\t\t::=======================================================::\n");
- printf("\t\t\t\t:: PROJECT NAME:SIMPLE CULCULATOR ::\n");
- printf("\t\t\t\t:: Istaiq Ahmed-ID:19105008 ::\n");
- printf("\t\t\t\t:: Farhan Labib-ID:19105025 ::\n");
- printf("\t\t\t\t::=======================================================::\n");
- printf("\t\t\t\t===========================================================\n");
- printf("press any key to clear screen:");
- char ch;
- fflush(stdin);
- scanf("%c",&ch);
- if(ch=='c')
- {
- system("cls");
- }
- system("COLOR 70");
- int X=1;
- char Calc_oprn;
- calculator_operations();
- while(X)
- {
- printf("\n");
- printf("%s ", KEY);
- Calc_oprn=getche();
- switch(Calc_oprn)
- {
- case '+':
- addition();
- break;
- case '-':
- subtraction();
- break;
- case '*':
- multiplication();
- break;
- case '/':
- division();
- break;
- case '?':
- modulus();
- break;
- case '!':
- factorial();
- break;
- case '^':
- power();
- break;
- case 'H':
- case 'h':
- calculator_operations();
- break;
- case 'r':
- root();
- break;
- case 'e':
- exponent();
- break;
- case 'l':
- logten();
- break;
- case 's':
- sine();
- break;
- case 'k':
- cosine();
- break;
- case 't':
- tangent();
- break;
- case 'n':
- cotangent();
- break;
- case 'a':
- secant();
- break;
- case 'b':
- cosec();
- break;
- case 'Q':
- case 'q':
- exit(0);
- break;
- case 'c':
- case 'C':
- system("cls");
- calculator_operations();
- break;
- default :
- system("cls");
- printf("\n**********You have entered unavailable option");
- printf("***********\n");
- printf("\n*****Please Enter any one of below available ");
- printf("options****\n");
- calculator_operations();
- }
- }
- }
- //Function Definitions
- void calculator_operations()
- {
- printf("\n Welcome to C calculator \n\n");
- printf("***** Press 'Q' or 'q' to quit ");
- printf("the program ********\n");
- printf("*** Press 'H' or 'h' to display ");
- printf("below options *****\n\n");
- printf("Enter 'C' or 'c' to clear the screen and");
- printf(" display available option \n\n");
- printf("Enter + symbol for Addition \n");
- printf("Enter - symbol for Subtraction \n");
- printf("Enter * symbol for Multiplication \n");
- printf("Enter / symbol for Division \n");
- printf("Enter ? symbol for Modulus\n");
- printf("Enter ^ symbol for Power \n");
- printf("Enter ! symbol for Factorial \n");
- printf("Enter r symbol for square root \n");
- printf("Enter e symbol for exponent \n");
- printf("Enter l symbol for logten \n");
- printf("Enter s symbol for sine \n");
- printf("Enter k symbol for cosine \n");
- printf("Enter t symbol for tangent \n");
- printf("Enter n symbol for cotangent \n");
- printf("Enter a symbol for secant \n");
- printf("Enter b symbol for cosec \n");
- }
- void addition()
- {
- int n, total=0, k=0, number;
- printf("\nEnter the number of elements you want to add:");
- scanf("%d",&n);
- printf("Please enter %d numbers one by one: \n",n);
- while(k<n)
- {
- scanf("%d",&number);
- total=total+number;
- k=k+1;
- }
- printf("Sum of %d numbers = %d \n",n,total);
- }
- void subtraction()
- {
- int a, b, c = 0;
- printf("\nPlease enter first number : ");
- scanf("%d", &a);
- printf("Please enter second number : ");
- scanf("%d", &b);
- c = a - b;
- printf("\n%d - %d = %d\n", a, b, c);
- }
- void multiplication()
- {
- int a, b, mul=0;
- printf("\nPlease enter first numb : ");
- scanf("%d", &a);
- printf("Please enter second number: ");
- scanf("%d", &b);
- mul=a*b;
- printf("\nMultiplication of entered numbers = %d\n",mul);
- }
- void division()
- {
- int a, b, d=0;
- printf("\nPlease enter first number : ");
- scanf("%d", &a);
- printf("Please enter second number : ");
- scanf("%d", &b);
- d=a/b;
- printf("\nDivision of entered numbers=%d\n",d);
- }
- void modulus()
- {
- int a, b, d=0;
- printf("\nPlease enter first number : ");
- scanf("%d", &a);
- printf("Please enter second number : ");
- scanf("%d", &b);
- d=a%b;
- printf("\nModulus of entered numbers = %d\n",d);
- }
- void power()
- {
- double a,num, p;
- printf("\nEnter two numbers to find the power \n");
- printf("number: ");
- scanf("%lf",&a);
- printf("power : ");
- scanf("%lf",&num);
- p=pow(a,num);
- printf("\n%lf to the power %lf = %lf \n",a,num,p);
- }
- int factorial()
- {
- int i,fact=1,num;
- printf("\nEnter a number to find factorial : ");
- scanf("%d",&num);
- if (num<0)
- {
- printf("\nPlease enter a positive number to");
- printf(" find factorial and try again. \n");
- printf("\nFactorial can't be found for negative");
- printf(" values. It can be only positive or 0 \n");
- return 1;
- }
- for(i=1; i<=num; i++)
- fact=fact*i;
- printf("\n");
- printf("Factorial of entered number %d is:%d\n",num,fact);
- return 0;
- }
- void root()
- {
- double first;
- printf("\nPlease Enter Only One Value: ");
- scanf("%lf",&first);
- printf("sprt(%.1lf) = %.1lf", first,sqrt(first));
- }
- void exponent()
- {
- float x;
- printf("\nEnter one number to find exponent: ");
- scanf("%f",&x);
- printf("%.2f",exp(x));
- }
- void logten()
- {
- double x;
- printf("\nEnter one number to find logten: ");
- scanf("%lf",&x);
- printf("%.2lf",log10(x));
- }
- void sine()
- {
- double x,d,val;
- printf("\nEnter one number to find sin: ");
- scanf("%lf",&x);
- if(x==90||x==180||x==0)
- {
- val = PI / 180;
- d=sin(x*val);
- printf("%.2lf",round(d));
- }
- else
- {
- val = PI / 180;
- d=sin(x*val);
- printf("%.2lf",d);
- }
- }
- void cosine()
- {
- double x,d,val;
- printf("\nEnter one number to find cos: ");
- scanf("%lf",&x);
- val = PI / 180;
- d=cos(x*val);
- printf("%.2lf",d);
- }
- void tangent()
- {
- double x,d,val;
- printf("\nEnter one number to find tan: ");
- scanf("%lf",&x);
- if(x==90||x==270)
- {
- printf("Math ERROR!");
- }
- else
- {
- val = PI / 180;
- d=tan(x*val);
- printf("%.2lf",d);
- }
- }
- void cotangent()
- {
- double x,d,val;
- printf("\nEnter one number to find cot: ");
- scanf("%lf",&x);
- if(x==0||x==180||x==360)
- {
- printf("Math ERROR!");
- }
- else
- {
- val = PI / 180;
- d=tan(x*val);
- printf("%.2lf",1/d);
- }
- }
- void secant()
- {
- double x,d,val;
- printf("\nEnter one number to find sec: ");
- scanf("%lf",&x);
- if(x==90||x==270)
- {
- printf("Math ERROR!");
- }
- else
- {
- val = PI / 180;
- d=cos(x*val);
- printf("%.2lf",1/d);
- }
- }
- void cosec()
- {
- double x,d,val;
- printf("\nEnter one number to find cosec: ");
- scanf("%lf",&x);
- if(x==0||x==180||x==360)
- {
- printf("Math ERROR!");
- }
- else
- {
- val = PI / 180;
- d=sin(x*val);
- printf("%.2lf",1/d);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement