So i wrote code to simplify a proper fraction in the form a/b provided by the user.
Code:
#include <stdio.h>
#include <stdlib.h>
int newnum, num, den, t, a, b;
int main()
{
printf(">> ");
scanf("%d/%d", &num, &den);
a=num;
b=den;
while(num!=den)
{
if(den>num)
{
t=den%newnum;
den=t;
if(den==1)
{
break;
}
}
if(den<num)
{
t=num%den;
num=t;
if(num==1)
{
break;
}
}
}
den=b/t;
num=a/t;
printf("%d/%d", num, den);
system ("PAUSE");
return 0;
}
When i compiled the code, it went through without any errors. But when I ran the .exe file and typed in 2/4, i didnt get 1/2. An error just popped up saying that the program needs to close. I compiled it and ran it on another computer to make sure but the same thing happened.
BTW, the algorithm used within the code to get the gcf (which is t in my code) is Euclids Algorithm.
Could there be something wrong with the code?