c语言求解答8.4 8.5,两题,本人初学者
2个回答
展开全部
8.4
#include <stdio.h>
int getgcd(int m, int n)
{
int temp = 0,r = 0,p = 0;
if(n < m)
{
temp = m;
m = n;
n = temp;
}
p = m * n;
while(m != 0)
{
r = n % m;
n = m;
m = r;
}
return n;
}
int main()
{
int m = 9, n = 21;
int gcd = 0;
gcd = getgcd(m,n);
printf("gcd:%d\n",gcd);
return 0;
}
8.5
#include <stdio.h>
int prime(int n)
{
int i ;
int flag = 1;
for(i = 2; i < n; i++)
{
if(n % i == 0)
flag = 0;
}
return flag;
}
int main()
{
int n = 83;
int result = 0;
result = prime(n);
printf("result:%d\n",result);
return 0;
}
追问
8.5呢
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询