C :: How To Store The Highest Prime Number

Feb 17, 2013

Basically, I am suppose to compute 10 numbers and find their highest prime number for each of them. I've already have the inputs working, and set up 2 arrays to store inputs and their highest prime number. But I am uncertain on how to find and store their highest prime number. How to start it off?

View 7 Replies


ADVERTISEMENT

C++ :: Find Highest Prime Of 600851475143

Jun 6, 2013

I have reduced it for lower numbers but for some reason with higher numbers when i get the program to out put all the primes they are in minuses!!!

I need a way to make this even faster, or maybe theres a better mathematical answer, I know that for numbers in their 1,000,000,000,000 have an average of 1 prime every 26.6 numbers (i think thats right there is 37,607,912,018 primes in the number 1,000,000,000,000) is there anyway i can utilize this??

#include <iostream>
using namespace std;
int main() {
int primeanswer = 1,p = 1;
for (int i=1;i<35; i++)

[Code] .....

View 19 Replies View Related

C++ :: Prime Number Program Not Working With Odd Non-prime Numbers

Dec 2, 2014

I have a program that gets prime numbers that doesn't work. It looks like it works for all prime numbers except odd non-prime ones. Here is the code:

Code:
#include <iostream>
using namespace std;
bool isPrime(int prime) {
while(true) {
int track = 0;

[Code] ...

View 3 Replies View Related

C/C++ :: Finding All Prime Numbers To Nth Prime Number

Aug 24, 2014

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.

View 1 Replies View Related

C :: Program That Allow User To Enter A Number N And Print Nth Prime Number

Nov 3, 2013

I need to write a program that will allow the user to enter a number "n" and the program tell you that the nth prime number is .....

EXAMPLE

user enters 55

printf("The 55th prime number is %i", variable");

View 1 Replies View Related

C++ :: Receive Number From User And Output Largest Prime Number

Nov 20, 2014

I am attempting to write code that receives a number from the user and outputs the largest prime number underneath the user's number. There are no errors in my code, but no matter what number is imputed, the program says the largest prime number is 1. I cannot find where the issue is in the code. Here is the code I wrote:

#include <cstdlib>
#include <iostream>
#include <cmath>
using namespace std;
bool isPrime(int num);//function prototype

[Code] ....

View 2 Replies View Related

C++ :: Finding Highest Number In Array

Aug 12, 2014

after staring at this for awhile, I can't figure out why it won't work. It prints out numbers from 0 to 100, but will print out an absurdly high number as the highest number, like 790 or 640. I can't see why.

Code:
#include <cstdlib>
#include <ctime>
#include <iostream>
using namespace std;
int find_highest(int array[]);
int find_highest (int array[], int size) {
int highest_num;
for (int i = 1; i < size; ++i) {
if (array[i] > array[i-1]) {

[code]....

View 1 Replies View Related

C++ :: Lowest And Highest Number Of A Series?

Feb 26, 2013

I'm having trouble, I want the inner loop to display the lowest and highest score. If I assign initial values for the high and low score, it won't always work (because if no/ all scores are above/ below my initial values...)

But without assigning initial values for highscore and lowscore, One of them will always be undefined during the first runthrough.

#include <iostream>
using namespace std;
const int AGRADE = 90;
const int BGRADE = 80;
const int CGRADE = 70;
const int DGRADE = 60;
int main() {

[code]....

how do i set this up so it stores a low and high score, and then compares those to each next number in the series?

View 6 Replies View Related

C++ :: Highest Digit In A Number (recursive Function)

Dec 23, 2013

I have this example problem in my school coursebook. How this program works? It determines the highest digit in a number.

#include <iostream>
using namespace std;
int m(int n) {
int a,b;

[Code] ....

View 4 Replies View Related

C++ :: Stuck On Getting Highest Number Output Using Array

Feb 25, 2014

Here is my code and everything works except i can not get the highest array number to be output. it always says 10.

My instructions are:

(1) Create a 10-integer array called data
(2) Set a pointer ptr to point to array data
(3) Output the elements in array data using pointer ptr
(4) Find the largest element in the array data using pointer ptr

#include <iostream>
#include <cstdlib>
using namespace std;

[Code].....

View 4 Replies View Related

C++ :: Find Prime Numbers Between Given Pair Of Numbers And Store Them Into Array?

Apr 18, 2014

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");

[Code] .....

View 1 Replies View Related

C++ :: Number Is Prime Or Not

Nov 7, 2013

#include <iostream>
using namespace std;
int main() {
//input output

[code]....

its supposed to tell whether the inputted number is prime or not

View 1 Replies View Related

C++ :: File Input / Output - Getting Highest And Lowest Number From A List Of 7 Numbers

Apr 16, 2013

I am currently confused on how to get the highest and lowest number from a list of 7 numbers for a File Output. Lets say i have 165 19 654 816 654 987 324. How would i get the 987 for the highest and the 19 as the lowest? Those numbers are not fixed numbers, i need to be able to input any combination of numbers and still be able to get the highest and lowest numbers from the list of 7 numbers.

View 1 Replies View Related

C++ :: Array Searching - Display Highest And Lowest Number From User Input

Aug 26, 2013

I am having a problem printing out the results for my code, It is supposed to print out the largest and smallest value in the array, but keeps giving me a value not entered and I don't know why.

//This program lets the user enter 10 numbers and then display the highest and lowest number.

#include <iostream>
#include<stdio.h>
using namespace std;
int main() {
const int NUM_ENTERED = 9;
int number[NUM_ENTERED], highestValue = number[0], lowestValue = number[0], count=0;

[Code] .....

View 2 Replies View Related

C++ :: Prime Factors Of A Number?

Oct 22, 2013

I have to create a program where I need to find the prime factors of a number and express it using exponents.

For example, for the number 1368 should output:

1368 = 2^3 * 3^2 * 19^1

This is my code:

void primeFact (int n){
int i;
int score = 0;

[Code].....

View 3 Replies View Related

C++ :: Prime Number Factorization

Dec 9, 2013

I am trying to factorize semi-prime numbers by using a brute force method and a square root method.The brute force method should start by multiplying all odd numbers between 1 and the semi-prime number. Meaning that 1 should multiply 3 then 5 then 7, etc. Then three should multiply 5 then 7 then 9 and so forth. The first number would never multiply a number equal to or less than itself.

bruteForce(int x){
f1 = 1;
f2 = f1 + 2;
while (f1 < x){
for (f2 = x; f2 <= x; f2-2){

[Code] ....

For my other algorithm, I want it to get the square root of the semi-prime and then start multiplying odd numbers around it. I made it so that the square root would have to be set to the next even number (in case it was a factor). If the product of the two odd numbers (a * b) is greater than the original semi-prime, I would multiply b by the next smaller number than a. Conversely, if the product of a and b is less than the original semi-prime, it will multiply a by the next odd number larger than b. This will repeat until the two correct factors of the original semi-prime are found.

Algorithm:

SquareRootFactorize(int x){
int N = x;
sqrtN = sqrt(N);
if (isOdd(sqrtN) == true)
sqrtN = sqrtN + 1;
f1 = sqrtN - 1;
f2 = sqrtN + 1;

[code].....

View 1 Replies View Related

C++ :: Prime Number Between Two Values

Mar 14, 2014

I wrote this program to print prime numbers between 2 and 10 but it only prints '3'. here is the code

#include<iostream>
#include<conio.h>
using namespace std;
int prime(int x, int y);
void main(){
int n=2;

[code].....

View 6 Replies View Related

C/C++ :: MPI Prime Number Search?

Mar 14, 2015

We are working on building a cluster and needed to create or find a program writen in C that we can run. I was thinking a program that finds prime numbers and insert them into a MySQL database. I have never worked with C so I don't know where to start or anything. I have a week to prove our project is worth keeping and our cluster is almost completely installed we just need to create a program.

View 4 Replies View Related

C++ :: Finding If A Number Is Prime Or Not

Oct 3, 2013

cin.ignore (10);
return 0;
}

Its not working

View 2 Replies View Related

C/C++ :: Prime Number Counter?

Feb 23, 2014

I have to write a program that asks the user to input a positive integer, counts how many primes there are before this integer, then divide the number of primes by the integer. Here's what I have so far:

int n;
int counter = 0;
cout<<"Enter a positive integer n.";
cin>>n;

[Code]....

the value of the integer counter is supposed to increase whenever a prime number is identified but it's increasing n times

View 8 Replies View Related

C++ :: Finding If A Number Is Prime?

Oct 3, 2013

We need it to say if the number is prime or not we need the equation for the if statement or if we have something else wrong to let me know.

#include <iostream>
using namespace std;
int main () {
int number;
bool countr;
for (countr = 0; countr <= 2; countr ++)

[Code] ....

View 1 Replies View Related

C/C++ :: Test If A Number Is A Prime?

Mar 13, 2014

my assignment is to print out the numbers from 2 to 20 stating if they are primes or not using loops and/or a function..once i execute, it throws the program into an infinite loop...

#include <iostream>
#include <cmath>
using namespace std;
bool prime(int n);
int main()
{
int i;

View 4 Replies View Related

C++ :: Faster Prime Number Algorithm

Oct 19, 2014

Can I possibly get a better implementation of a prime number detecting algorithm than the one I already have below?

Code:
#include <cstdio>
#include <cstdlib>
int main() {
int no, high, low;
int divisor;

[Code] .....

View 8 Replies View Related

C :: Calculate Prime Number Using Loops

Oct 10, 2013

how would I write a while() loop that calculates the sum of all prime numbers from 1 - 50.

View 5 Replies View Related

C++ :: Choose A Number To Check If Prime Or Not

Oct 20, 2014

#include "stdafx.h"
#include "iostream"
using namespace std;
int main (){
int x;
int i;
int e;

[Code] ....

is the logic good ? and why the program is looping

View 3 Replies View Related

C/C++ :: Finding Prime Factors Of A Number

Mar 18, 2015

I am trying to find the prime factors of a number but when i compile and run my code after i enter a number it just closes it doesn't print ....

included library : [URL] ....

#include "std_lib_facilities.h";
void prime(int n) {
int result;
result = 0;
int i;
for (i = 2; i == n*n; ++i)

[Code] .....

View 14 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved