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++涓嬭皟璇曢氲繃锛屾渶澶у叕绾︽暟璁$畻浣跨敤镄勬槸娆у嚑閲屽痉绠楁硶锛堟暟璁哄熀纭鐭ヨ瘑锛夛纴鐪嬭繃灏辨槑锏戒简銆
热点内容