作业帮 > 综合 > 作业

设计模块设计一个模块cmnfctr,计算给定的两个整数的所有公约数.CalcCommonFactorOf()用来设定参与

来源:学生作业帮 编辑:搜搜做题作业网作业帮 分类:综合作业 时间:2024/06/04 09:50:50
设计模块
设计一个模块cmnfctr,计算给定的两个整数的所有公约数.CalcCommonFactorOf()用来设定参与计算的两个整数,然后每调用一次NextCommonFactor()得到一个公约数,按照从小到大的顺序给出.用下面的代码调用此模块
int sub
CalcCommonFactorOf(100,50);
while ((sub=NextCommonFactor())>0)
{
static int countter = 1;
printf("common factor %d is %d",counter++,sub);
}
这个是cmnfctr.c
static int a=0,b=0,c;
void CalcCommonFactorof(int x,int y)
{
a = x;
b = y;
c = x > y y :x;
}
int NextCommonFactor()
{
if (a
设计模块设计一个模块cmnfctr,计算给定的两个整数的所有公约数.CalcCommonFactorOf()用来设定参与
答案:
#include
void CalcCommonFactorof(int x, int y);
int NextCommonFactor(void);
static int a=0,b=0,c;
void CalcCommonFactorof(int x, int y)
{
a = x;
b = y;
c = x > y ? y : x;
}
int NextCommonFactor()
{
if (a