1. Prime factor

i am trying to make program that checks if the number is a prime or not:
Code:
```int asal(int a,int b){
int x;
for(x=2;x<a;x++){
if(a%x!=0){return a;}
else {return b;}}}```
but when i do this asal(9,1)=>it returns 9 implying it a prime number
i stared at the code for about 10 min.s couldnt find it so i said good people in c board could help me (i wish)

note(In Turkish(asal)==In English(prime)(note(i am Turkish)))
(i tried make it look like C programming

2. Your loop never executes more than once -- in your if statement you return in either case.

3. Code:
`if(a%x!=0){return a;}`
You got your logic wrong. You want there to be a remainder in division.

4. Originally Posted by alperen1994
but when i do this asal(9,1)=>it returns 9 implying it a prime number
Of course. The first thing that happens is 9%2, which the answer is not zero so it returns a.

5. so how can i do it????
(i am asking because i want learn new ways to make it)
(i am in the computer olimpics this year,wish me luck)

6. Originally Posted by alperen1994
(i am in the computer olimpics this year,wish me luck)
You'll need it

Probably you wanted == instead of !=, since if the number can be divided without a remainder (so modulus = 0), it cannot be prime.

7. first of all if you want it to be a program that interacts with the user you should add a "number" which is entered by the user..

your for loop has a mistake, it should be ;(...;x<=(a-1);...)

and a%x==0