如果结果是浮点数,如何停止划分?
我已经对此代码进行了编程,但是它部分向我展示了结果50/3向我展示16,而我想介绍以停止这种操作(如果浮动)。该怎么办?
#include <stdio.h>
int main(){
int number, divisor, x, y;
printf("Enter the Natural Number to find Divisors\n");
scanf("%d", &number);
printf("Enter the Natural Number to divide for\n");
scanf("%d", &x);
printf("Divisors of the number %d are \n", number);
y=number/x;
for (divisor = 1; divisor<=number;divisor++){
if((number%divisor)==0){
printf("%d\n", divisor);
}
else{
continue; }
}
printf("The result of the division is %d", y);
return 0;
}
i have programmed this code but it show me partially the result as example 50/3 show me 16 while i want to introduce to stop this kind of operations if float. How to do?
#include <stdio.h>
int main(){
int number, divisor, x, y;
printf("Enter the Natural Number to find Divisors\n");
scanf("%d", &number);
printf("Enter the Natural Number to divide for\n");
scanf("%d", &x);
printf("Divisors of the number %d are \n", number);
y=number/x;
for (divisor = 1; divisor<=number;divisor++){
if((number%divisor)==0){
printf("%d\n", divisor);
}
else{
continue; }
}
printf("The result of the division is %d", y);
return 0;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这就是我必须阅读您的代码多远:
您认为由0的部门做什么?
但是让我们继续前进:
如果字符串常数为null,则该测试是永远不会的。
总体而言,您似乎正在尝试测试
X
是素数。在这种情况下,您需要在2
上启动循环并测试其余部分:This is how far I have to read your code:
What do you think a division by 0 should do?
But lets keep going:
This tests if the string constant is NULL, which can never be.
Overall it looks like you are trying to test if
x
is a prime. In that case you need to start the loop at2
and test the remainder: