直接上代码
static void Main(string[] args) { int x = 640; int y = 480; int max = GetLargestCommonDivisor(x,y); int b_x = x / max; int b_y = y / max; Console.WriteLine("图片宽高比为:【"+b_x+":"+b_y+"】"); } /*求最大公约数*/ static int GetLargestCommonDivisor(int n1, int n2) { int max = n1 > n2 ? n1 : n2; int min = n1 < n2 ? n1 : n2; int remainder; while (min != 0) { remainder = max % min; max = min; min = remainder; } return max; }
微信扫码查看本文
发表评论