c語言判斷互質
發布時間: 2024-05-09 07:44:38
A. 鍒ゆ柇涓や釜鏁癮,b鏄鍚︿負浜掕川鏁扮殑紼嬪簭錛岀敤C璇璦緙栧啓錛
涓や釜鏁頒簰璐錛屽氨鏄璇翠袱涓鏁扮殑娌℃湁鍏鍏卞洜瀛愶紝鍗蟲渶澶у叕綰︽暟鏄1
紼嬪簭濡備笅錛
#include <stdio.h>
int GCD(int x,int y)//鏈澶у叕綰︽暟鍑芥暟錛屾у嚑閲屽痙綆楁硶
{
int a,b,c;
if(x>y)
{a=x,b=y;}
else
{a=y,b=x;}
while ((a%b)!=0)
{
c=a%b;
a=b;
b=c;
}
return b;
}
int main()
{
int m,n;
printf("please input two positive numbers:");
scanf("%d%d",&m,&n);
if(GCD(m,n)>1)
printf("涓や釜鏁頒笉鏄浜掕川鐨勩\n");
else
printf("涓や釜鏁版槸浜掕川鐨勩\n");
}
杈撳叆紺轟緥錛100 3
杈撳嚭錛氫袱涓鏁版槸浜掕川鐨勩
紼嬪簭鍦―EV C++涓嬭皟璇曢氳繃錛屾渶澶у叕綰︽暟璁$畻浣跨敤鐨勬槸嬈у嚑閲屽痙綆楁硶錛堟暟璁哄熀紜鐭ヨ瘑錛夛紝鐪嬭繃灝辨槑鐧戒簡銆
熱點內容