Q for a source code in an exercise

Joined
Dec 15, 2023
Messages
1
Reaction score
0
i have this code and when i change the loop in the isprime function to i<x the program does not give me the prime numbers but if i leave it right there it works just fine

#include <stdio.h>

int isprime(int x);

main()
{
int a,b,i;
printf("give start:");
scanf("%d",&a);
printf("give finish:");
scanf("%d",&b);

for(i=a; i<=b; i++)
{
if(isprime(i))
printf("\nprime number=%d",i);
}
}

int isprime(int x)
{
int i;
int check;
check=1;
for(i=2; i<x/2; i++);

if(x%i==0)
check=0;


return check;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top