Problem with determining prime numbers

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <iostream>
using namespace std;

int count=0;

int s(int n){
	for(int i=1;i<=n;i++){
		if(n%i==0){
			count++;
		}
	}
	if (count==2){
		return n;
	}
	
           
}

int main(){
	for(int a=1;a<13195;a++){
		if(13195%a==0){
           s(a);
		}
	}
	system("pause");
}


Function above main should determine is the number prime or not but i is not working,can someone help,it's frustrating me.
Last edited on
I have no idea what the above fuction even SHOULD do, and I don't want to know, becouse of 3 reasons:
1) no code tags
2) you are TOTALY overcompilcating too much more than a lot!
3) the function does some strange things, and it never returns
The function shall return a bool and have a for loop from 2 to sqrt(n), in which you check the modulo of n and the current iteration number: if it's zero, return false. At the end of the function, outside of the for loop, you return true. It's that simple. As I already said, I dont'k know and don't care what you wrote in your function becouse it's ridicuolous!
Sorry for bad code,I just dont know what to do when i get all the numbers that are factors of some number,I mean I dont know how to from that sequence extract prime ones.Thats all,but anyway thanks!
Topic archived. No new replies allowed.