#define VERSION "0.10" #define N 100 #include int derive (int n); void split (int value, int *a, int *b); int main () { int n, res; int sgn; char again; do { sgn = 1; printf ("Enter an integer: "); scanf ("%d", &n); if (n < 0) sgn = -1; res = derive (sgn * n); res = sgn * res; printf ("The arithmetic derivative of %d is: %d", n, res); getchar (); printf ("\nAgain? [y/n] "); scanf ("%c", &again); } while (again != 'n'); printf ("\n\n\nversion: %s", VERSION); } int derive (int n){ int a = 1, b = 1; switch (n) { case 0: return 1; break; case 1: return 0; break; default: split (n, &a, &b); if (b > 1){ // not a prime n = derive (a) * b + a * derive (b); } else { n = 1; } return n; break; } } void split (int value, int *a, int *b) { int i = 2; int j = 0; do { if (value % i == 0) { *a = i; *b = value / *a; j++; } i++; } while (j == 0); }