【发布时间】:2021-10-27 11:17:04
【问题描述】:
为什么不是所有区间都显示在输出中?
#include <stdio.h>
int checkprimenumbers(int i);
int main()
{
// declar varabiels
int n1,n2,a,Tayp;
// input from user
printf("Enter to integer values: ");
scanf("%d\n%d",&n1,&n2);
printf("Prime numbers between %d and %d are: ", n1, n2);
// condition statment
for (a= n1 + 1;a < n2; ++a )
{
Tayp = checkprimenumbers(a);
if (Tayp == 1)
printf("%d ", a) ;
return 0;
}
}
// user-defined function
int checkprimenumbers(int i)
{
int b , Type =1 ;
for (b = 2 ; b <= i/2; ++b )
{
if( i%b == 0)
{
Type =0;
break;
}
}
return Type;
}
程序有效,但所有间隔均未显示 这是调试后的输出
输入整数值:12
30
12 到 30 之间的质数是:13
【问题讨论】:
标签: c function for-loop user-defined-functions