我在C程序中應該要求兩個數字並找到它們的LCM和GCF。但是,在請求這兩個數字之後,代碼將以非零狀態退出。 Link to code here,任何幫助將不勝感激。C代碼以非零狀態退出
#include <stdio.h>
int main()
{
//Declare things
int i;
int num1,num2 = 0;
int foundLCM = 0;
int foundGCF = 0;
//Ask for input
printf("\nEnter a positive integer: ");
scanf("%i", &num1);
printf("\nEnter another positive integer: ");
scanf("%i", &num2);
//Set i to the bigger number
if(num1 >= num2)
{
int i = num1;
}
else
{
int i = num2;
}
//find the GCF
while(foundGCF == 0)
{
if(num1%i == 0 && num2%i == 0)
{
printf("\nGreatest Common Factor: %i\n", i);
foundGCF = 1;
}
i--;
}
//Find the LCM
while(foundLCM == 0)
{
if(i%num1 == 0 && i%num2 == 0)
{
printf("Lowest Common Multiple: %i", i);
foundLCM = 1;
}
i++;
}
//Kill
return 0;
}
請在這裏發佈代碼 – Steve