練習問題
#include <stdio.h>
void yurika(int , int );
int main()
{
int a, b;
for (a = 1; a < 101; a++)
for (b = 1; b < 101; b++)
yurika(a,b);
return 0;
}
void yurika(int a, int b)
{
int a1, a2, i;
printf("√%2d / √%2d = ", a, b);
if (a == b) { printf("1\n"); return; }
if (a % b == 0) { a = a / b; b = 1; }
else a = a * b;
for (i = 1; i*i <= a; i++)
if (a % (i*i) == 0) { a1 = i; a2 = a / (i*i); }
for (i = 1; i < 15; i++)
if (a1 % i == 0 && b % i == 0) { a1 = a1 / i; b = b / i; }
if (a1 == 1 && b == 1) { printf("√%d\n", a2); return; }
else if (a2 == 1 && b == 1) { printf("%d\n", a1); return; }
else if (b == 1) { printf("%d√%d\n", a1, a2); return; }
else if (a2 == 1) { printf("%d / %d", a1, b); return; }
else if (a1 == 1) { printf("√%d / %d\n", a2, b); return; }
else printf("%d√%d / %d\n", a1, a2, b);
return;
}