Implemented GCD and added it to your program,to reduce the fraction.
Code:
#include <stdio.h>
#include <stdlib.h>
int gcd(int,int);
#define TRUE 1
#define FALSE 0
int main(int argc, char *argv[])
{
int a,b,ans,left,g,n,d;
printf("Numerator\n");
scanf("%d", &a);
printf("Denominator\n");
scanf("%d", &b);
ans = a / b;
left = a%b;
g=gcd(left,b);
if(left==0)
printf("\n%d\n", ans);
else if (g==1 && left > 0)
{
printf("\n%d %d/%d\n", ans, left, b);
}
else
{
left=left/g;
b=b/g;
printf("\n%d %d/%d\n", ans, left, b);
}
system("PAUSE");
return 0;
}
int gcd(int n,int d)
{
int r; //remainder
while((n%d!=0) || (d<=0))
{
r=n%d;
n=d;
d=r;
}
if(n%d==0)
{
return d;
}
else
return FALSE;
}