-
Notifications
You must be signed in to change notification settings - Fork 0
/
digit cancelling fraction.cpp
89 lines (75 loc) · 1.23 KB
/
digit cancelling fraction.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include<stdio.h>
#include<conio.h>
main()
{
int i,j;
float num=0,test=0;
int nom=1,denom=1;
float mul_fraction;
int a=0,b=0,c=0,d=0;
for(i=10;i<100;i++)
{
a=i/10; //digit number 2
b=i-a*10; //digit number 1
for(j=10;j<i;j++)
{
num=j/float(i);
c=j/10;
d=j-c*10;
if(a==c&&(a!=0||c!=0))
{
test=d/float(b);
if(test<1&&test==num)
{
printf("%d/%d=%d/%d=%f\n",b,d,j,i,num);
mul_fraction*=test;
nom*=d;
denom*=b;
}
}
if(a==d&&(a!=0||d!=0))
{
test=c/float(b);
if(test<1&&test==num)
{
printf("%d/%d=%d/%d=%f\n",b,c,j,i,num);
mul_fraction*=test;
nom*=c;
denom*=b;
}
}
if(b==c&&(b!=0||c!=0))
{
test=d/float(a);
if(test<1&&test==num)
{
printf("%d/%d=%d/%d=%f\n",a,d,j,i,num);
mul_fraction*=test;
nom*=d;
denom*=a;
}
}
if(b==d&&(b!=0||d!=0))
{
test=c/float(a);
if(test<1&&test==num)
{
mul_fraction*=test;
printf("%d/%d=%d/%d=%f\n",a,c,j,i,num);
nom*=c;
denom*=a;
}
}
}
}
for(i=2;i<100;i++)
{
if(nom%i==0&&denom%i==0)
{
nom/=i;
denom/=i;
i--;
}
}
printf(" the answer is ----> %d",denom);
}