这是一个检查共素对的程序.
我正在尝试编写一个程序来接收整数输入,直到用户输入0,这很容易在数组的帮助下解决(我已经用数组做了)因为一次只能读取一个值并检查.使用数组它只是:
for(i = 0; i < n-1; i++)
然后比较v[i]和v[i+1]
我试图在没有数组的情况下应用这种精确的检查算法,但是,读取两个值并比较它们,不知何故,只有当我多次输入0,有时两次,有时三次时,循环才会结束.
#include <stdio.h>
int gcd1(int a, int b) //function containing Euclid's algorithm
{
while (b != 0)
{
int temp = a%b;
a = b;
b = temp;
}
return a;
}
int main(int argc, char * argv[])
{
int num1, num2; /* both of these vars would otherwise have a non-zero
value if I was using Try Nr.1 written in bold below was applied */
int …Run Code Online (Sandbox Code Playgroud)