我从函数 isprime 返回值 1 或 0(当它不是素数时为 0,当它是素数时为 1)但是当我打印 x 的返回值(isprime 的返回值)时,它与我从 isprime 返回的不同。为什么?
#include<stdio.h>
int isprime(int b);
main()
{
int a,rem,i;
printf("enter the number");
scanf("%d", &a);
for(i = 1; i < a; i++)
{
rem = a % i;
if(rem == 0)
{
int x = isprime(i);
printf(" value of x returned for i = %d is %d", i, x);
if(x = 1)
{
printf("%d\n", i);
}
}
}
return (0);
}
/**
*
*returns 1 if b is prime else returns 0
*/
int isprime(int b)
{
int x, count = 0;
printf("input recieved %d \n", b);
for(x = 1; x <= b; x++)
{
if (b % x == 0)
{
count = count + 1;
}
printf("the value of count is %d\n", count);
}
if(count == 2) {
printf("returning the value as 1\n");
return 1;
}
else {
printf("returning the value as 0\n");
return 0;
}
}