Linked Questions

4 votes
3 answers
49k views

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?
Waypoint's user avatar
  • 17.8k
2 votes
4 answers
319 views

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++) { ...
Lydia's user avatar
  • 81
0 votes
1 answer
199 views

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 ...
user avatar
1 vote
2 answers
132 views

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. ...
user3338188's user avatar
42 votes
6 answers
13k views

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....
Devyn Collier Johnson's user avatar
10 votes
2 answers
18k views

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 ...
Nick's user avatar
  • 1,544
16 votes
1 answer
8k views

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 ...
user1172468's user avatar
  • 5,484
4 votes
9 answers
1k views

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 (...
nkminion's user avatar
8 votes
4 answers
964 views

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(...
Z boson's user avatar
  • 34k
1 vote
4 answers
4k views

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 ...
user3348699's user avatar
3 votes
5 answers
2k views

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%...
Painguy's user avatar
  • 567
-2 votes
7 answers
7k views

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; ...
Dreaded Harvester's user avatar
-4 votes
3 answers
23k views

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, ...
Yeez's user avatar
  • 302
2 votes
5 answers
984 views

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? ...
chanzerre's user avatar
  • 2,429

15 30 50 per page