Skip to content

Commit

Permalink
added some new functions..
Browse files Browse the repository at this point in the history
  • Loading branch information
Krrishdhaneja authored Sep 21, 2020
1 parent ccbe197 commit dacbab6
Showing 1 changed file with 176 additions and 21 deletions.
197 changes: 176 additions & 21 deletions calculator.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main(int argc, char const *argv[])
{
double num1;
Expand All @@ -13,15 +14,18 @@ int main(int argc, char const *argv[])
printf("square(type 5)\n");
printf("square root(type 6)\n");
printf("exponentiation(type 7)\n");
printf("absolute value(type 8)\n");
printf("cube(type 9)\n");
printf("cube root(type 10)\n");
printf("\n");
printf("type the first num:\n");
printf("type the first number:\n");
scanf("%lf", &num1);
printf("type the num2:\n");
printf("type the second number:\n");
scanf("%lf", &num2);
printf("type the operator(type 8 to know all the operators)\n");
printf("type the operator(type 0 to know all the operators):\n");
scanf("%lf", &op);

if (op == 8)
if (op == 0)
{
printf("plus(type 1)\n");
printf("minus(type 2)\n");
Expand All @@ -30,40 +34,85 @@ int main(int argc, char const *argv[])
printf("square(type 5)\n");
printf("square root(type 6)\n");
printf("exponentiation(type 7)\n");
double z;
printf("type 1 to exit:\n");
scanf("%lf", &z);
if (z == 1)
{
printf("Have A Good Day");
}
}
else if (op == 1)
{
printf("%lf", num1 + num2);
printf("%lf\n", num1 + num2);
double z;
printf("type 1 to exit:\n");
scanf("%lf", &z);
if (z == 1)
{
printf("Have A Good Day");
}
}
else if (op == 2)
{
printf("%lf", num1 - num2);
printf("%lf\n", num1 - num2);
double z;
printf("type 1 to exit:\n");
scanf("%lf", &z);
if (z == 1)
{
printf("Have A Good Day");
}
}
else if (op == 3)
{
printf("%lf", num1 * num2);
printf("%lf\n", num1 * num2);
double z;
printf("type 1 to exit:\n");
scanf("%lf", &z);
if (z == 1)
{
printf("Have A Good Day");
}
}
else if (op == 4)
{
printf("%lf", num1 / num2);
printf("%lf\n", num1 / num2);
double z;
printf("type 1 to exit:\n");
scanf("%lf", &z);
if (z == 1)
{
printf("Have A Good Day");
}
}
else if (op == 5)
{
double d;
printf("type 1 for num1 to be squared or type 2 for num2 be squared:\n");
scanf("%lf",&d);
if (d==1)
scanf("%lf", &d);
if (d == 1)
{
printf("%lf",pow(num1,2));
printf("%lf\n", pow(num1, 2));
double z;
printf("type 1 to exit:\n");
scanf("%lf", &z);
if (z == 1)
{
printf("Have A Good Day");
}
}
else if (d==2)
else if (d == 2)
{
printf("%lf", pow(num2, 2));
printf("%lf\n", pow(num2, 2));
double z;
printf("type 1 to exit:\n");
scanf("%lf", &z);
if (z == 1)
{
printf("Have A Good Day");
}
}




}
else if (op == 6)
{
Expand All @@ -72,11 +121,25 @@ int main(int argc, char const *argv[])
scanf("%lf", &k);
if (k == 1)
{
printf("%lf", sqrt(num1));
printf("%lf\n", sqrt(num1));
double z;
printf("type 1 to exit:\n");
scanf("%lf", &z);
if (z == 1)
{
printf("Have A Good Day");
}
}
else if (k == 2)
{
printf("%lf", sqrt(num2));
printf("%lf\n", sqrt(num2));
double z;
printf("type 1 to exit:\n");
scanf("%lf", &z);
if (z == 1)
{
printf("Have A Good Day");
}
}
else
{
Expand All @@ -85,13 +148,105 @@ int main(int argc, char const *argv[])
}
else if (op == 7)
{
printf("%lf", pow(num1, num2));
printf("%lf\n", pow(num1, num2));
double z;
printf("type 1 to exit:\n");
scanf("%lf", &z);
if (z == 1)
{
printf("Have A Good Day");
}
}
else if (op == 8)
{
double q;

printf("type the number of which you wan to get absolute value(type [1] for num1 or [2] for num2):\n");
scanf("%lf", &q);
if (q == 1)
{
printf("%lf\n", abs(num1));
double z;
printf("type 1 to exit:\n");
scanf("%lf", &z);
if (z == 1)
{
printf("Have A Good Day");
}
}
else if (q == 2)
{
printf("%lf\n", abs(num2));
double z;
printf("type 1 to exit:\n");
scanf("%lf", &z);
if (z == 1)
{
printf("Have A Good Day");
}
}
}
else if (op == 9)
{
double w;
printf("which number you want to be cubed(type [1] for num1 or [2] for num2):\n");
scanf("%lf", &w);
if (w == 1)
{
printf("%lf\n", pow(num1, 3));
double z;
printf("type 1 to exit:\n");
scanf("%lf", &z);
if (z == 1)
{
printf("Have A Good Day");
}
}
else if (w == 2)
{
printf("%lf\n", pow(num2, 3));
double z;
printf("type 1 to exit:\n");
scanf("%lf", &z);
if (z == 1)
{
printf("Have A Good Day");
}
}
}
else if (op == 10)
{
double e;
printf("which number you want to be cube rooted(type[1] for num1 or [2] for num2):\n");
scanf("%lf", &e);
if (e == 1)
{
printf("%lf\n", cbrt(num1));
double z;
printf("type 1 to exit:\n");
scanf("%lf", &z);
if (z == 1)
{
printf("Have A Good Day");
}
}
else if (e == 2)
{
printf("%lf\n", cbrt(num2));
double z;
printf("type 1 to exit:\n");
scanf("%lf", &z);
if (z == 1)
{
printf("Have A Good Day");
}
}
}

else
{
printf("nothing to do");
}

return 0;
}

0 comments on commit dacbab6

Please sign in to comment.