So if i write a Loop to calculate Prime Numbers in order, is there any way possible for this to happen in a shorter period of time.
The loop that i constructed took about 11hrs on a Win 7 2GB ram machine to calculate about 150,000 primes, could this be done any faster................
I wrote a program which sends a starting and ending range to other processes and the processes calculate the prime numbers in that range and return the count of prime numbers to the head process, process 0. But this is not working properly at the moment. I realize I still have to split up the range based on how many processes I have...I still have not figured out how I want to set that up. I
Code:
#include <stdio.h> #include <stdlib.h> #include <mpi.h> int isPrime(int num); int main(int argc, char **argv){ }
I'm a new coder for C++, and I've recently learned java before starting this programming language. I'm attempting to find all prime numbers up to the number a user enters (i.e. User enters 10, System shows "1,2,3,5,7"),
#include <iostream> #include <cstdlib> using namespace std; int main(int argc, char** argv) { int num; cout << "Enter a positive number." << endl;
[Code] ....
I've been looking at my forloop, and I can't seem to pinpoint the problem with it.
Find all the prime numbers between a given pair of numbers. Numbers should be read in from an input file called "numbers.txt" and find all the prime numbers between them. Store the prime numbers in an array, then sort the array from greatest to least. Display the array before and after the sort.
I'm stuck on how to put the prime numbers into an array.
The input file has the numbers 1 & 100.
Here's what I have so far.
#include <iostream> #include <fstream> using namespace std; int main() { ifstream fin; fin.open("numbers.txt");
I want to program an advanced calculator. I'd like to enter some more complex expressions like -17+3*4*(4-sqrt(4) and i want, that mathematical operations are done the correct order, so at first 4-sqrt(4) is calculated, then 3*4*2 and then -17 is subtracted.
Problem 1: Convert a string into a mathematical calculation Problem 2: Calculate in the correct order
How would I do that (I dont expect perfecly precoded calculators from you, just the way how to do it)
Google search just delivers primitive calculations with entry methods like
Enter first number 1 Enter operator + Enter second number 2
I was going through a book I have about C trying to learn about arrays, and one of the first few examples of what could been done with an array was showing how to use an array to generate a list of prime numbers. I've been staring at this program for about an hour trying to understand how it works (it does), but the workings of one for loop within the program.
Code:
#include <stdio.h> #include <stdbool.h> int main () { int p, i, primes[50], primeIndex = 2; bool isPrime;
[Code]...
So that is saying in order for this loop to go on, really two conditions must be met since there's that && operator. isPrime must be true (I think that's what it means by just having "isPrime" and not setting it equal to anything) and p / primes[i] must be greater than or equal to primes[i].So at the beginning of the loop, since i = 1, p = 5 (as per surrounding loop), and prime[i] = 3 ( as per the variable assignment at the beginning of the program ), the loop condition would be "isPrime && 5 / 3 >= 3"
"5 / 3 >= 3" The loop should stop right there! 1.666666667 is NOT greater than or equal to 3!
#include <stdio.h> int find_next_prime(int num); int is_prime(int num); int main()
[Code]......
How would I go about counting the number of times a factorial has a specific prime number?
For example, 5! = (2^3)*(3^1)*(5^1), 6! = (2^4)*(3^2)*(5^1).
How would I begin to design my find_prime_count function in order to count how many times each occurs? My program is to read in a number between (2<=N<=100) from a text file and output the results exactly like above which I still have to figure out after, I'll assume I have to use fscanf.
I have an assignment where I have to use two for loops. I need to ask the user for any two numbers and be able to list all the numbers in between and their factors and state whether or not the number is prime or not.
The object is to have the user enter in the number of days then the day the calendar would start on. This part I was able to achieve and run okay. Once I wanted to get the values/days that were prime to have a P besides them this is where I ran into trouble. In this case P stands for prime numbers.
The issue I have is that some of the values that are prime have the correct P but others have the P as well such as 9, 15, and 25 - which are not prime numbers.
I was able to create a program that checked for prime numbers separately but I had issues merging them. Below is the merged code followed by the prime checker.
#include <stdio.h> int main(int argc, const char * argv[]) { int i, N, Start; int j, GetNumber, PrimeNumber = 0;
Given a number "n" supplied by the user, write all the prime numbers less than or equal to "n"
not at all how to make the number I enter me for the numbers that I need even a couple makes the prime number if the command is used repeat for but and decision making but the truth is that I can think of no way to do for this exercise is that the prime numbers are those numbers which are divided only by 1 and themselves also
until the moment I have this code
#include <stdio.h> #include <stdlib.h> main(){ int n; n=0; printf("enter the desired number: "); scanf("%f",&n); system("pause"); }
I have written a program that finds the divisers of non-prime numbers and outputs them. However, the output is only one diviser per line(because of the repetition to find the divbisers), but the instructor wants us to have 5 to 10 divisers per line. How can i write this loop so it will only output the divisers in one line?
A prime number is a number greater than 1 which is only evenly divisible by 1 and itself. For this assignment you will find which numbers from 2 to n (where n is a user-specified number) are prime. Ask the user for a number, n, greater than 2. Keep asking for a number until a number greater than 2 is provided. Assume that the user will only enter numbers (that is, you do not need to check if a user enters text).
Use a loop to iterate on a variable, i, from 2 through n. For each iteration, check all numbers from 2 through i to determine whether the number is prime. If it is prime, print out i and the word "Prime". Use the modulus operator, %, to determine if a number is prime
Example output:
Please enter a number larger than two: -939 Please enter a number larger than two: 2 Please enter a number larger than two: 20 2 Prime 3 Prime 5 Prime 7 Prime 11 Prime 13 Prime 17 Prime 19 Prime
This is what I have so far. I suppose i'm not really understanding how to continue with the second for loop. The first one just prints out a list of numbers from 2 to the number designated by the user. In my case that variable is user_input.
I wrote some code for class to find prime numbers.The teacher says that I need to revise my code with the requirement below: use a bit array to store the prime number checking. The bit array will also be in the heap. Use the max value of an unsigned 32-bt integer (UINT_MAX) to be the maximum size of the prime number you want to check.
I currently need separating my Prime numbers in group for my assignment. I absolutely do not know how to do this. I am able to find out if the number I used is prime and see how many prime number there are between 1-100 and then 1-1000 (168 primes) and so on. The thing that I need to do is find the number of prime numbers between 101-200, 201-300, 301-400, and so on until 901-100 and have it show on screen. Here is the exact assignment that I’m supposed to find out:
Assignment:
Write a C++ program to calculate and display the number of primes from 1 to 100,000, separated in groups of 100, 10 groups per line. To be more precise, on the first line of output, display the number of primes between 1 and 100, 101 and 200, etc., up to 901 to 1000. Then display the average primes per group. For example, there are 168 primes from 1 to 1000, so the average number of primes per group of 100 (or percentage) is 16.8. Then repeat the process for the groups of 100 between 1001 to 1100, 1101 to 1200, etc., for all groups of 1000 all the way up to 100,000. Your results should be as presented below, under testing.
Testing:
The output of your program should be the following, according to my calculations. Each group (g1, g2, etc.) is the number of primes in a group of 100 numbers. For example in line 1, g1 is the group from 1 to 100, g2 is the group 101 to 200, etc. For line 2, g1 is the group 1001 to 1100, g2 is 1101 to 1200, and g10 is the group from 1901 to 2000.
g1 g2 g3 g4 g5 g6 g7 g8 g9 g10 Average Primes ---------------------------------------------------------------- 25 21 16 16 17 14 16 14 15 14 16.8 for 1 to 1000 16 12 15 11 17 12 15 12 12 13 13.5 for 1001 to 2000 14 10 15 15 10 11 15 14 12 11 12.7 for 2001 to 3000 12 10 11 15 11 14 13 12 11 11 12.0 for 3001 to 4000 … … … 7 10 5 10 7 11 7 6 11 8 8.2 for 97001 to 98000 7 5 9 9 11 8 7 8 12 11 8.7 for 98001 to 99000 8 11 8 8 7 9 8 10 10 8 8.7 for 99001 to 100000
Total number of primes from 1 to 100000: 9592 Average primes per 1000: 95.92 Percentage of primes from 1 to 100000: 9.59
Here is my code that I have done so far:
#include <iostream> #include <string> #include <cmath> using namespace std; bool isPrime(long candidate); long primeCount (long start, long end);
I am trying to implement a method that removes all the prime numbers from a vector. They are all numbers from 0 to num, where num in given by the user.
void findVectorPrimes(int num, set<int>& primes) { int squareRoot = sqrt(num); vector <int> v; vector<int>::iterator m = v.begin();
[code].....
There is a separate method that fills the vector.Its giving me an error and I can't seem to figure it out. Here is the error...
seive.cc:121:35: error: no match for âoperator*â in âv.std::vector<_Tp, _Alloc>::begin<int, std::allocator<int> >().__gnu_cxx::__normal_iterator<_Iterator, _Container>::operator+<int*, std::vector<int> >((* &((__gnu_cxx::__normal_iterator<int*, std::vector<int> >::difference_type)m.__gnu_cxx::__normal_iterator<_Iterator, _Container>::operator*<int*, std::vector<int> >()))) * kâ
We were asked to make a program which displays the prime numbers within the range you inputted... like for example i entered 20 as the upper limit and 1 as the lower, then the program must display all prime numbers within 20 and 1..
and so my problem is, i get to display the prime numbers, but 2, 3, 5, and 7 can't because it think it's with the if statement i made within the loop? (Code below)
#include<iostream.h> #include<conio.h> void prime (int up, int low); main() { clrscr(); int Upper, Lower, i;