【发布时间】:2013-01-31 04:20:27
【问题描述】:
我的寻找素因数的程序已经设置好了……我唯一需要做的就是这种类型的输出:
你想试试其他号码吗?说 Y(es) 或 N(o): y //要求另一个号码(再次通过程序)
你想试试其他号码吗?说 Y(es) 或 N(o):n //感谢您使用我的程序。再见!
我在下面尝试过...当我输入 n 时,它会输出正确的结果。但是,如果我输入“y”,它只会说 n 所做的同样的事情......我如何循环整个程序而不将程序代码放在我拥有的这个 while 循环中?所以当我按 y 时它会再次通过程序?
int main() {
unsigned num;
char response;
do{
printf("Please enter a positive integer greater than 1 and less than 2000: ");
scanf("%d", &num);
if (num > 1 && num < 2000){
printf("The distinctive prime facters are given below: \n");
printDistinctPrimeFactors(num);
printf("All of the prime factors are given below: \n");
printPrimeFactors(num);
}
else{
printf("Sorry that number does not fall within the given range. \n");
}
printf("Do you want to try another number? Say Y(es) or N(o): \n");
response = getchar();
getchar();
}
while(response == 'Y' || response == 'y');
printf("Thank you for using my program. Goodbye!");
return 0;
} /* main() */
【问题讨论】: