Linked Questions
21 questions linked to/from C - determine if a number is prime
4 votes
3 answers
49k views
C - how to test easily if it is prime-number? [duplicate]
Possible Duplicates: C - determine if a number is prime Is there any way to test easily in C whether a selected number is prime or not?
2 votes
4 answers
319 views
Finding prime numbers in c++ [duplicate]
I'm currently learning c++ for the first time and I've written a cpp bool function to find if an integer is a prime number. The code was: bool isPrime(int n) { for (int i = 2; i < n; i++) { ...
0 votes
1 answer
199 views
Prime or not Prime output slow [duplicate]
This is C program. This is my code in the below. I used nano in terminal. When I compile and test with ./a.out 9872349901 but it's took me exact one minute to get a result... Does anybody know why is ...
1 vote
2 answers
132 views
Testing Primality in C++ [duplicate]
Can anyone help me out? I am trying to test primality but I cant seem to get this to work. For whatever reason, whenever I run it, it runs fine as long as I start with a number that is not prime. ...
42 votes
6 answers
13k views
In C, why is "signed int" faster than "unsigned int"?
In C, why is signed int faster than unsigned int? True, I know that this has been asked and answered multiple times on this website (links below). However, most people said that there is no difference....
10 votes
2 answers
18k views
"invalid controlling predicate" compiler error using OpenMP
I'm creating a basic prime number checker, based on C - determine if a number is prime , but utilising OpenMP. int isPrime(int value) { omp_set_num_threads(4); #pragma omp parallel for ...
16 votes
1 answer
8k views
Parallel Algorithms for Generating Prime Numbers (possibly using Hadoop's map reduce)
Generating Prime numbers is a toy problem that I often attempt from time to time, especially when experimenting with a new programming language, platform or style. I was thinking of attempting to ...
4 votes
9 answers
1k views
Wrote a program to print prime numbers, How do I make it better?
I started learning C the previous day and I wrote a program to print within a given range. Minimum and Maximum of range is given by user. #include <stdio.h> int check(int number) { if (...
8 votes
4 answers
964 views
Conditional tests in primality by trial division
My question is about the conditional test in trial division. There seems to be some debate on what conditional test to employ. Let's look at the code for this from RosettaCode. int is_prime(...
1 vote
4 answers
4k views
Average of prime numbers in an array
Well, the problem is the above. To sum it up, it compiles, but I guess my main idea is just wrong. What I'm trying to do with that code is: I want the person to give us the elements of the array, how ...
3 votes
5 answers
2k views
Prime number in C
int prime(unsigned long long n){ unsigned val=1, divisor=7; if(n==2 || n==3) return 1; //n=2, n=3 (special cases). if(n<2 || !(n%2 && n%3)) return 0; //if(n<2 || n%2==0 || n%...
-2 votes
7 answers
7k views
C program to check whether a number is prime or not
I used the following code and it showed numbers like 49 as prime and not composite. I am new to programming so please help me with the correct code. #include <stdio.h> int main() { int n; ...
-4 votes
3 answers
23k views
Warning: comparison between pointer and integer [enabled by default]
So, I'm just practicing something in C language (I'm a beginner), but I'm now stuck on this program: #include <stdio.h> #include <string.h> int main(){ int numbers[12] = {2, 3, 5, 7, ...
2 votes
5 answers
984 views
C-greatest prime factor of a given number
I have written the following code to compute the greatest prime factor of a number supplied through standard input but it is taking ages to execute.How can i reduce the execution time of the program? ...