به راحتی
با تقسیم متوالی ب.م.م رو میگیری همون روش درختی که سال اول راهنمایی یادمون دادن به کتاب ریاضی سال اول راهنمایی مراجعه کنید
#include <iostream>
using namespace std;
int gcd ( int a, int b )
{
int c;
while ( a != 0 ) {
c = a; a = b%a; b = c;
}
return b;
}
int main(){
int a,b;
cout << "Please Enter Soorat!!!?";
cin >>a;
cout << "Please Enter makhraj!!!?";
cin >>b;
cout << "\nkasre sade shode barabar ast ba : \n\n";
cout << a/gcd(a,b) << " taghsimbar " << b/gcd(a,b) << endl ;
cout << "\nya\n\n" << a/gcd(a,b) << "/"<< b/gcd(a,b)<<endl ;
return 0;
}
اینم توی c#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication3
{
class Program
{
static int GCD(int a, int b)
{
int Rem;
while( b != 0 )
{
Rem = a % b;
a = b;
b = Rem;
}
return a;
}
static void Main(string[] args)
{
int x, y;
Console.WriteLine("Please Enter a soorat!!!?");
x = int.Parse(Console.ReadLine());
Console.WriteLine("Please Enter an makhraj!!!?");
y = int.Parse(Console.ReadLine());
Console.Write("fractione sade shode barabar ast ba:\n");
Console.WriteLine("{0}/{1} isEqual {2}/{3}", x, y, x/GCD(x, y),y/GCD(x,y));
Console.ReadKey();
}
}
}