C/C++ :: Program To Check Number Is Prime Or Not

Jan 12, 2013

What is the minimum range of numbers which we need to go necessarily to check either a number is prime or not?(for all integers) ....

View 6 Replies


ADVERTISEMENT

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++ :: 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 :: 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++ :: Program Which Print Out All Prime Numbers Less Than Or Equal To Given Number

Nov 11, 2013

how to make a programm in native c++ which print out all prime numbers less than or equal to given number????????

View 5 Replies View Related

C++ :: Program To Tell Whether Number Is Prime Or Not - Illegal Structure Operation

Mar 2, 2013

In 83rd line message says: "Illegal Structure operation". But I didn't use any structures! How to correct it?

#include<iostream.h>
#include<conio.h>
#include<math.h>
int prime(int);
int reverse(int) ;
int power(int,int);
int rectangle(int,int);
int square(int);
int circle(int);
void tables(int);

[Code] ....

View 6 Replies View Related

C++ :: Write Program Which Tells User If Number They Input Is Prime Or Not?

May 2, 2014

So I need to write a program which tells the user if the number they input is prime or not. I have done so and included the code below. My problem is that I need to allow the user to input if they want to enter another number after the first one using y or n and I am having trouble figure it out.

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

[Code].....

View 5 Replies View Related

C++ :: CPP Program To Check Whether A Number Is Palindrome Or Not?

Feb 12, 2014

I could not find the mistake in this program....

Code:
//cpp program to check whether a number is palindrome or not
#include<iostream.h>
#include<conio.h>
//the class
class palindrome

[Code] ....

View 4 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++ :: 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++ :: 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++ :: 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 :: 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 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/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

C++ :: Show Prime Number Between A And B And Count Them

Dec 24, 2014

This shows any prime number between a and b and also counts them*/

#include <iostream>
using namespace std;
int main(){
int a;
int b;

[Code] .....

View 1 Replies View Related

C :: How To Find Biggest Prime Factor Of A Number

Feb 10, 2015

i want to write a program which find the biggest prime factor of a number for example the biggest prime factor of six is three or the biggest prime factor of fifteen is five. What is my program bug

Code:

#include <stdio.h> // main functions
#include <math.h> // for sqrt function
int main()
{
int i, j, k, f; // F = Flag;
printf("Enter K

[Code]...

View 9 Replies View Related

C++ :: Find Largest Prime Number K Of Array 1

Aug 30, 2013

While finding the primes , I do not know how to make it into one array so that...

View 7 Replies View Related







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