hi,
my problem is when i press m or M (min or max) and input negetive numbers (like -88, -6...)
i get stack overflow
im asking why???
Code:
#include <stdio.h>
#include <math.h>
#include <string.h>
int gcd(int, int);
int main()
{
int x, y, result, power, user_quit = 1;
char c;
while (user_quit)
{
printf("please enter char and 2 integers: ");
_flushall();
c = getchar();
if ((c == 'q') || (c == 'Q'))
{
printf("finish!");
user_quit = 0;
getchar();
}
else
{
scanf("%d%d", &x, &y);
int min = (x < y ? x : y);
int max = (x > y ? x : y);
result = gcd(x, y);
power = (double)pow(x, y);
switch (c)
{
case 'A':
case 'a':
printf("The Average of %d and %d is: %d.\n", x, y, (x + y) / 2);
break;
case '*':
printf("The Multiply of %d and %d is: %d.\n", x, y, x*y);
break;
case 'm':
printf("The Minimum of %d and %d is: %d.\n", x, y, min);
break;
case 'M':
printf("The Maximum of %d and %d is: %d.\n", x, y, max);
break;
case 'G':
printf("The GCD of %d and %d is: %d.\n", x, y, result);
break;
case '^':
printf("The Power of %d and %d is: %lf.\n", x, y,(double) power);
break;
default: printf("illegal\n");
}
}
}
getchar();
return 0;
}
int gcd(int x, int y)
{
while (x != y)
{
if (x > y)
{
return gcd(x - y, y);
}
else
{
return gcd(x, y - x);
}
}
return x;
}