Για σας παιδιά!
Λιπόν μετά από αρκετό διάβασμα και εξάσκηση στη C αποφάσησα να φτιάξω ένα απλό Calculator.
Το ονόμασα CL-Calc (Command Line Calculator).
Λοιπόν εδώ είναι ο κώδικας:
- Κώδικας: Επιλογή όλων
#include <stdio.h>
#include <math.h>
void main (void) {
double x, y;
char c, e=0;
puts ("Usage:\n======\n\nAddition:\t\t+ Addendum1 Addendum2\nSubtraction:\t\t- Reducer Subtrahend\nMultiplication:\t\t* Factor1 Factor2\nDivision:\t\t/ Divisor Divident\nPercentage:\t\t% Number\nPower:\t\t\t^ Base Exponent\nSquare root:\t\tr Number\nQuit:\t\t\tx");
do {
printf ("\n\n>>> ");
scanf ("%s", &c);
switch (c) {
case '+' :
scanf ("%lf %lf", &x, &y);
printf ("Total: %g", x + y);
break;
case '-' :
scanf ("%lf %lf", &x, &y);
printf ("Difference: %g", x - y);
break;
case '*' :
scanf ("%lf %lf", &x, &y);
printf ("Product: %g", x * y);
break;
case '/' :
scanf ("%lf %lf", &x, &y);
if (y == 0) printf ("Invalid divisor...");
else printf ("Quotient: %g | Remainder: %d", x / y, (int) x % (int) y);
break;
case '%' :
scanf ("%lf", &x);
printf ("Percentage: %g", x / 100);
break;
case '^' :
scanf ("%lf %lf", &x, &y);
printf ("Result: %g", pow (x, y) );
break;
case 'r' :
scanf ("%lf", &x);
printf ("Result: %g", sqrt (x) );
break;
case 'x' :
e=1;
break;
default:
printf ("Wrong option chosen...");
break;
}
}
while (!e);
}
Και ένα από τον MigF1.
Κάντε το compile με την εντολή
gcc -lm <ονομα αρχείου>.c