/*
讓客戶滿意是我們工作的目標(biāo),不斷超越客戶的期望值來自于我們對(duì)這個(gè)行業(yè)的熱愛。我們立志把好的技術(shù)通過有效、簡(jiǎn)單的方式提供給客戶,將通過不懈努力成為客戶在信息化領(lǐng)域值得信任、有價(jià)值的長(zhǎng)期合作伙伴,公司提供的服務(wù)項(xiàng)目有:域名注冊(cè)、雅安服務(wù)器托管、營(yíng)銷軟件、網(wǎng)站建設(shè)、歷下網(wǎng)站維護(hù)、網(wǎng)站推廣。
21 17
是
2 4
不是
9 3
不是
13 39
不是
q
Press any key to continue
*/
#include?stdio.h
int?MaxFactor(int?m,int?n)?{?//?最大公約數(shù)
int?t;
if(n??m)?{?t?=?n;n?=?m;m?=?t;?}????
for(t?=?m;t??0;t--)?{
if(m?%?t?==?0??n?%?t?==?0)
return?t;
}
return?1;?//?永遠(yuǎn)得不到執(zhí)行。
}
void?is_huzhishu(int?x,int?y,int?*res)?{
if(1?==?MaxFactor(x,y))?*res?=?1;
else?*res?=?0;
}
int?main()?{
int?m,n,res;
while(scanf("%d%d",m,n)?==?2)?{
is_huzhishu(m,n,res);
if(res)?printf("是\n");
else?printf("不是\n");
}
return?0;
}
#includestdio.h
#includestring.h
#includemalloc.h
#includeconio.h
#includemath.h
#include?stdlib.h?
#include?time.h
#include?stdlib.h
void?is_huzhishu(int?x,int?y,?int*?jieguo)
{
int?temp;
while(?y?!=?0)
{
temp?=?y;
y?=?x?%?y;
x?=?temp;
}
if(x?==?1)
{
*jieguo?=?1;
}
else
{
*jieguo?=?0;
}
}
int?main(void)
{
int?x,y,jieguo;
printf("請(qǐng)輸入兩個(gè)正整數(shù),以英文逗號(hào)分隔\n");
scanf("%d,%d",?x,?y);
is_huzhishu(x,?y,?jieguo);
if(jieguo)
{
printf("YES\n\n");
}
else
{
printf("NO\n\n");?
}
return?0;
}
兩個(gè)數(shù)互質(zhì),就是說兩個(gè)數(shù)的沒有公共因子,即最大公約數(shù)是1
程序如下:
#include stdio.h
int GCD(int x,int y)//最大公約數(shù)函數(shù),歐幾里德算法
{
int a,b,c;
if(xy)
{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("兩個(gè)數(shù)不是互質(zhì)的。\n");
else
printf("兩個(gè)數(shù)是互質(zhì)的。\n");
}
輸入示例:100 3
輸出:兩個(gè)數(shù)是互質(zhì)的。
程序在DEV C++下調(diào)試通過,最大公約數(shù)計(jì)算使用的是歐幾里德算法(數(shù)論基礎(chǔ)知識(shí)),看過就明白了。
本文題目:c語言互為質(zhì)數(shù)的函數(shù) c語言中質(zhì)數(shù)
鏈接地址:http://muchs.cn/article20/dospjco.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供外貿(mào)網(wǎng)站建設(shè)、動(dòng)態(tài)網(wǎng)站、網(wǎng)站導(dǎo)航、Google、虛擬主機(jī)、做網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)