C :: Write A Code To Find All The Prime Numbers Before A User Entered Number

Apr 9, 2014

I am trying to write code to find all the prime numbers before a user entered number. I started with a working program and when I tried to create a function, it got all messed up.

Code:

#include <stdio.h>
int is_prime( int num );
int get_positive_integer(void);
int main( ) {
int upper; /* upper limit to check */
int num; /* current number to check */
int isprime;
/* used to flag if number is prime or not */

[Code]...

It says the error is on line 23

View 6 Replies


ADVERTISEMENT

C/C++ :: Find Max Number Entered By User And Terminate When Negative Number Entered

Jul 15, 2014

I am trying to find the max number entered by the user, and it should terminate when a negative number is entered. For my code, it will just end when the user inputs a lower number than the previous. i.e.- 10 20 15 "The highest number is 20" when it should be "10 20 5 40 15 -1" "The highest number is 40". No arrays or do/while loops either.

#include <iostream>
using namespace std;
int Max(int x);
int main() {
int x;

[Code] ....

View 9 Replies View Related

C :: Find The Largest And Smallest Number Entered By User?

Mar 6, 2015

How to find the largest and smallest number entered by a user. So far I'm able to add, find the average and count how many numbers are entered.

I'm just having trouble with find the max and min. I tried if statements and it breaks the program will it wont let me exit the while loop or the program will do a force close after entering a value.

Code:

#include <stdio.h>
#include <stdlib.h>
int main(){

int maxNum=0, minNum=0, value, count=0, sum=0;
double average;

[Code] ....

View 4 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/C++ :: Find Prime Factors Of Number Input By User?

Apr 21, 2014

find the prime factors of the number input by the user. This time, we are going to have the user input a number, and the program will find all prime numbers from 2 to that number and prime factors of the number input by the user

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

[Code]......

View 5 Replies View Related

C++ :: Write A Source Code That Find Smallest / Largest And Average Of Numbers From Array

May 13, 2014

im trying to write a source code that find the smallest, largest and average of numbers in array. the code runs fine, but it is not giving the highest number and the the average should include only four number excluding highest and smallest number from the array.

void OlympicJudging() // Olympic Judging {
int numbers [6];
double average, sum = 0;
int temp;
for(int i = 0; i < 6; i++){
cout << "Please type a value for scores: ";
cin >> numbers[i];

[Code]...

View 5 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++ :: 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++ :: Find And Delete All Vowels In A Word That Is Entered By User

Mar 26, 2013

The program should find and delete all vowels in a word that is user entered. This is what I have so far and I know it should be essentially this format I just don't know how to set enteredword and word equal to each other.

#include <string>
#include <iostream>
using namespace std;
void vowelremover(string&);
int main () {
string word;

[Code] ....

View 3 Replies View Related

C++ :: Find Unequal Elements In Array Entered By User

Jan 12, 2014

I would like to know the algorithm or flow for finding unequal elements in an array entered by user. I tried using for loop but didn't get the expected output

Code:
#include <iostream>
#include <string>
using namespace std;
int main() {
int a[10],b[10]; //array of integer elements

[Code] ....

View 6 Replies View Related

C :: Find Prime Numbers - How To Use Bit Array

Aug 19, 2013

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.

Code:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <pthread.h>
#include <getopt.h>
#include <ctype.h>
#include <stdint.h>

//function to set all non-primes to 0
void *zero_multiples(void *threadid);

[Code] .....

View 4 Replies View Related

C++ :: Find All Prime Numbers In A Range

Oct 17, 2013

I am trying to create a program that lists all prime numbers within a range of two number. Why the below program isn't working?

#include <iostream>
using namespace std;
int main(){
int high_range;
int low_range;
int w;

[Code] .....

View 3 Replies View Related

C++ :: Find All Prime Numbers From 1 To 1000?

Jan 9, 2013

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

[Code].....

View 10 Replies View Related

C++ :: Find The Prime Numbers Between Two Values?

Jan 26, 2013

i did a code that determine if the number is prime or not, and i have to do a one that finding the prime numbers between two variables .

the first code:

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

[Code].....

View 4 Replies View Related

C++ :: Program To Find And Delete All Vowels In A Word That Is User Entered

Mar 25, 2013

The program should find and delete all vowels in a word that is user entered. This is what I have so far and I know it should be essentially this format I just don't know how to set entered word and word equal to each other.

Code:

#include <string>
#include <iostream>
using namespace std;
void vowelremover(string&);
string word;
int main ()
{//string word;

[Code]....

View 3 Replies View Related

C/C++ :: Find Sum Of Prime Factors Of User Input Integer

Sep 16, 2014

As an assignment for school , I've to write a program to find the sum prime factors of a user input integer.

E.g. 20 = 2 x 2 x 5 , Sum = 2 + 2 + 5 = 9
E.g. 10 = 2 x 5 , Sum = 2 + 5 = 7

My method for finding the result is as follows :

- Divide the number by increasing values if int i , starting from i=2.

- Once I get a value of i that can divide the number without giving me a remainder , I add this value of i to int sum and divide the number by i.

- I will repeat this process until the user input value is equal to 1.

My code is as shown:

#include<stdio.h>
int primecheck(int n); // Function to check if i is prime
int primesum(int n); // Function to sum the values of i that are prime
int main(void) {
int n;
int sum;
printf("Enter a number (> 1): "); //Prompting and scanning user input ,n
scanf("%d",&n);
sum = primesum(n);

[Code] .....

But for some reason I keep getting an incorrect result, it's as if it is missing out the last factor for each case.

Eg. 20 = 2 x 2 x 5 , the result I get is 4 , which is 2+2
Eg. 40 = 2 x 2 x 2 x 5 , the result I get is 6 , which is 2+2+2;

I've looked through my code numerous times.

View 7 Replies View Related

C++ :: Find All Prime Numbers Between 1 And 100 Using Sieve Of Eratosthenes

Dec 23, 2014

I had to write a program to find all the primes between 1 and 100 using the sieve of Eratosthenes so I wrote this program :

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

// find all the primes number using Eratosthenes
int main() {
vector<bool> numbers(101);

[Code] .....

My problem is that if I try to modify the program to find all the primes between 1 and max (setting the size of the vector uqual to max) my program becomes slower and I would like to listen by other people some possible solution to don't use vector in this program, the author hasn't shown me yet how to delete a value from a vector so I just used this method to solve the problem.

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++ :: 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++ :: Find Prime Numbers From 0 To 100 Million - Running On 8 Cores?

May 11, 2012

I made a program which finds the prime numbers from 0 to 100 million, and ran it on my laptop (core 2 duo, 1.83ghz, 2gb ram). It takes around 35 seconds for it to sieve all the non-prime numbers on my laptop.

I then ran the same program on a windows server, 2x 64 bit Intel Xeon Quad Core Processors @ 1.6 ghz, 6gb ram, and it takes the same amount of time, even when I set the priority to high and the affinity to all 8 cores, it seems to only use one core for the processing, is there any way to make it use all 8 cores at close to 100%?

View 11 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

C/C++ :: Calculate Result Of 2 Numbers That User Entered

Oct 29, 2012

In this exercise, write a rational number calculator that ask the user to enter two rational number:

a/b + c/d

and produce the result:

(ad+bc)/bd

View 10 Replies View Related

C/C++ :: Calculate Percentage Of Even Numbers Entered By User In Array

Nov 18, 2014

exercise in c: write a program which calculates % of even numbers entered by a user in an array;

1) check if user hasn't entered float value; if has issue warning;
2) give the option for user to press "stop" to exit program any time.

int c,sk[100],i,sum1=0, sum2=0, rel;
printf ("How many numbers will you enter?
");
scanf ("%d", &c);
printf ("Enter %d numbers (to exit program press - stop)
", c);

[Code] ....

View 1 Replies View Related

C++ :: Printing The First N Prime Numbers (user Input)

Jan 15, 2014

//Finding prime numbers
#include <iostream>
using namespace std;

[Code]....

/*The program currently prints all the prime numbers up to n (For example, if 7 is entered, it prints out: 1, 2, 3, 5, 7. What I want it to do, is print out the first 7 numbers; 1, 2, 3, 5, 7, 11, 13.

View 1 Replies View Related







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